BufferedWriter br = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(file)), 40960);
char[] str = new char[40959];
for (int i = 0 ; i < 40959; i++) {
str[i] = 'a';
}
long time = System.currentTimeMillis();
br.write(str);
System.out.println(System.currentTimeMillis() - time);
time = System.currentTimeMillis();
br.flush();
System.out.println(System.currentTimeMillis() - time);
输出:
0
2