public static void main(String[] args) {
String content[] = {"好久不见了","最近好吗","常联系"};
File file = new File("E:/workspace/Java从入门到精通/mynote.txt");
try{
FileWriter fw = new FileWriter(file);
BufferedWriter bufferfw = new BufferedWriter(fw);
for(int k=0;k<content.length;k++){
bufferfw.write(content[k]);
bufferfw.newLine();
}
bufferfw.close();
fw.close();
}catch(Exception e)
{
e.printStackTrace();
}
try{
FileReader fr = new FileReader(file);
BufferedReader bufferfr = new BufferedReader(fr);
String s = null;
int i=0;
while((s=bufferfr.readLine())!=null)
{
i++;
System.out.println("第"+i+"行:"+s);
}
bufferfr.close();
fr.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}