我在 Java 中使用 PrintWriter 尝试将一些字符串写入文本文件,但是当我打开文本文件时它是空的。
这是我的代码:
public void save(String fileName) throws FileNotFoundException{
PrintWriter out1 = new PrintWriter("aSB.txt");
out1.println("The Pupil's information is listed below:");
for (Pupil pup : Pupils) {
out1.println(pup.getFirstName() + " " + pup.getLastName());
}
out1.println("End");
out1.println("The Club's information is listed below:");
for (Club clu : Clubs) {
out1.println(clu.getName());
}
out1.close();
}
为什么文件名是空的?