import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileString {
public static void main(String[] args) {
// TODO Auto-generated method stub
outByFileDataOutputStream("I:\\0.bin");
}
private static void outByFileDataOutputStream(String filePath) {
File target = new File(filePath);
if (target.exists() && target.isFile()) {
boolean flag = target.delete();
}
try {
if (target.createNewFile()) {
FileOutputStream out =new FileOutputStream(filePath, true);
while (target.length() < 5000000) {
for (int i = 0; i <= 255; i++) {
byte num = (byte) i;
byte[] bytes = new byte[16];
for (int j = 0; j < 16; j++) {
bytes[j] = (byte) i;
}
out.write(bytes);
}
}
out.flush();
out.close();
System.out.println("chenggong");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
为测试用的,利用java生成大小限制为5m内的二进制文件