package cn.io; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; //BufferedWriter的简单使用 public class Test4 { public static void main(String[] args) { FileWriter fw=null; BufferedWriter bw = null; try { fw = new FileWriter("F:\\hao.txt"); bw = new BufferedWriter(fw); for(int x=0;x<10;x++){ bw.write(x+"hello world"); bw.newLine();//写入换行符 bw.flush(); } } catch (IOException e) { e.toString(); } finally{ if(bw!=null){ try { bw.close(); } catch (IOException e) { e.toString(); } } if(fw!=null){ try { fw.close(); } catch (IOException e) { e.toString(); } } } } }