java生成自定义大小的文件
package com.es.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class test {
public static void main(String[] args) {
File f1 = new File("C:/Users/HJJ/Pictures/Saved Pictures/test.doc");
try {
FileOutputStream fos = new FileOutputStream(f1);
if (!f1.exists()) {
try {
f1.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
byte[] buffer = new byte[1024 * 20];
long start = System.currentTimeMillis();
for (int i = 0; i < 1024; i++) {
fos.write(buffer);
fos.flush();
}
long end = System.currentTimeMillis();
long time = end - start;
System.out.println("写入时间:" + time + "ms");
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}