Language/Java

dumy file 생성기

아르비스 2014. 11. 12. 09:17


public class FileMakeUtil {

private static Logger logger = LoggerFactory.getLogger(FileMakeUtil.class);

private FileMakeUtil() {

}

public static void makefile(String path, long sizeMega) {

checkDirectory(path); 

File file = new File(path);

FileWriter fw;

try {

fw = new FileWriter(file);

BufferedWriter bw = new BufferedWriter(fw);

long megaSize = sizeMega * (1024*1024);

char data = 'A';

for (long i = 0; i < megaSize; i++) {

bw.append(data);

if(data > 'Z') {

data = 'A';

} else {

data++;

}

}


bw.close();

fw.close();

} catch (IOException e) {

logger.error("Error to Make File : {} ", path, e);

}

}


private static void checkDirectory(String path) {

File temp = new File(path);

String dir = temp.getParent();

File directory = new File(dir);

if(!directory.exists()){

directory.mkdirs();

}

}

}