public class Student {
public static void main(String[] args) {
// TODO Auto-generated method stub
String content[] = {"好久不见","最近好吗","常联系",};
File file = new File("word.txt");
try {
FileWriter fw = new FileWriter(file);
BufferedWriter bufw = new BufferedWriter(fw);
for(int i=0;i<content.length;i++){
bufw.write(content[i]);
bufw.newLine();
}
bufw.close();
fw.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
try {
FileReader fr = new FileReader(file);
BufferedReader bufr = new BufferedReader(fr);
String string = null;
int i=0;
while((string = bufr.readLine())!=null){
i++;
System.out.println("第" + i + "行" + string);
}
bufr.close();
fr.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}