1 21 22 package net.sourceforge.cobertura.util; 23 24 import java.io.File ; 25 import java.io.FileWriter ; 26 import java.io.IOException ; 27 28 import org.apache.log4j.Logger; 29 30 37 public class FileFlooder 38 { 39 40 private static final Logger LOGGER = Logger.getLogger(FileFlooder.class); 41 42 public static void flood(String directory, String fileName, String fileExt, int numOfFiles, 43 int linesPerFile) 44 { 45 File dir = new File (directory); 46 if (dir.exists() && dir.isDirectory()) 47 { 48 for (int i = 1; i <= numOfFiles; i++) 49 { 50 FileWriter writer = null; 51 try 52 { 53 File file = new File (directory + "/" + fileName + i + "." + fileExt); 54 LOGGER.info("Writing file: " + file.getAbsolutePath()); 55 writer = new FileWriter (file); 56 for (int l = 1; l <= linesPerFile; l++) 57 { 58 writer.write("This is a test file. blah.... blah.... blah....\n"); 59 } 60 } 61 catch (IOException ioe) 62 { 63 LOGGER.error("Error while writing file.", ioe); 64 } 65 finally 66 { 67 if (writer != null) 68 try 69 { 70 writer.close(); 71 } 72 catch (IOException e) 73 { 74 } 76 } 77 } 78 } 79 } 80 81 public static void main(String [] args) 82 { 83 FileFlooder.flood(".", "file", "txt", 100, 1000); 84 System.out.println("done"); 85 } 86 87 } 88 | Popular Tags |