日期:2014-05-20 浏览次数:20795 次
//缓冲流对文件进行读写
import java.io.*;
public class Example12_7{
public static void main(String args[]){
File file=new File("sb3.txt");
String content[]={"大爷好","二爷我不好","三爷最近我心里烦","四爷我最近手头紧"};
String content_2[]=new String[content.length];
try{
FileWriter outOne=new FileWriter(file);
BufferedWriter outTwo=new BufferedWriter(outOne);
for(String s:content){
System.out.println(s);
outTwo.write(s); //conetent内容没有被写入文件?哪里出问题了?
outTwo.newLine();
}
outOne.close();
outTwo.close();
FileReader inOne=new FileReader(file);
BufferedReader inTwo=new BufferedReader(inOne);
for(int i=0;i<content.length;i++){
content_2[i]=inTwo.readLine();
System.out.println(content_2[i]);
}
inOne.close();
inOne.close();
}
catch(IOException e){};
}
}