try (PrintWriter writer = new PrintWriter("student.txt")) { writer.println("姓名 语文 数学 英语 总分 "); for (Student s : set) { writer.println(s.getName() + " " + s.getChinese() + " " + s.getMath() + " " + s.getEnglish() + " " + s.getTotalScore()); } } catch (IOException e) { e.printStackTrace(); }
今天学到了一种简便的输出输出流方法,mark一下~