生成文件-java自动生成多个相同文件

来源:互联网 发布:出国留学知乎 编辑:程序博客网 时间:2024/06/11 23:03

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;


public class PicProduct implements Runnable {

public static void main(String[] args) throws IOException {

byte[] buf = new byte[60*1024];
for(int b=0;b<buf.length;b++){
buf[b]='k';
}
for (int i = 1; i <= 100; i++) {

File f = new File("C:\\pictures\\2014\\01\\1" + "\\" + i + ".txt");
FileOutputStream   fos   =   null; 
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
try {
fos=new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fos.write(buf);
} catch (IOException e) {
e.printStackTrace();
}

try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}

}
System.err.println("create  files num"+i+"over!!");
}
}

public String getFileUUid()
{
UUID uuid=UUID.randomUUID();
return uuid.toString();
}


public void run() {
// TODO 自动生成方法存根

}


}
0 0