//不使用缓冲区,用时100MS public static void main(String[] args) { Writer writer = null; try { Long startTime = System.currentTimeMillis(); writer = new FileWriter("D:\zp_project\rt.txt"); for (int i = 0; i <500000 ; i++) { writer.write(i); } Long endTime = System.currentTimeMillis(); System.out.println(endTime-startTime); } catch (IOException e) { e.printStackTrace(); }finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } //使用缓冲区 用时33MS public static void main(String[] args) { Writer writer = null; BufferedWriter bufferedWriter = null; try { Long start = System.currentTimeMillis(); writer = new FileWriter("D:\zp_project\bf.txt"); bufferedWriter = new BufferedWriter(writer); for (int i = 0; i <500000 ; i++) { bufferedWriter.write(i); } Long end = System.currentTimeMillis(); System.out.println(end - start); } catch (IOException e) { e.printStackTrace(); }finally { try { bufferedWriter.close(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }