日期:2014-05-20 浏览次数:20841 次
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.io.FileWriter;
public class WriteFile {
public static void main(String[] args) {
long times = 3000;
for (int i = 0; i < times; i++) {
//write1(Integer.toString(i+1));
write2(Integer.toString(i+1));
}
System.out.println("finished!");
}
private static void write1(String content) {
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter("d:\\1.txt", true);
bw = new BufferedWriter(fw);
bw.write(content);
bw.newLine();
bw.flush();
bw.close();
fw.close();
} catch (Exception e) {
// TODO: handle exception
}
}
private static synchronized void write2(String content) {
FileWriter fw = null;
PrintWriter pw = null;
try {
fw = new FileWriter("d:\\2.txt", true);
pw = new PrintWriter(fw);
pw.println(content);
pw.close();
fw.close();
} catch (Exception e) {
// TODO: handle exception
}
}
}