public void Writerdemo(){
double startime = System.currentTimeMillis();
String s1="F:/tt.txt";
String str = "imooc";
File file =new File(s1);
if(file.exists()){
}else{
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
String id=null;
int n=1;
try {
FileWriter fw = new FileWriter(file,true);
BufferedWriter bufw = new BufferedWriter(fw);
for(int i=1;i<1000;i++){
if(i%99==0){
s1="F:/tt"+n+".txt";
bufw = new BufferedWriter(new FileWriter(new File(s1),true));
n++;
}
id= "ID:"+i+"\t";
String s = id+str;
bufw.write(s);
bufw.newLine();//换行
}
bufw.close();
fw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
double endtime = System.currentTimeMillis();
System.out.println("程序运行时间:"+(endtime-startime)/1000+"秒");
}
程序运行后每个文件之间总有十几条或几十条数据没有了,不知道什么出问题了 ,求指教!!
相关分类