我们发现PrintStream有一个可以接受file的构造函数,这说我们可以直接输入到文件中,而不用构造什么FileOutputStream,那么怎样直接输入呢?这个还要System.setOut()配合。
- PrintStream ps = new PrintStream("f://zzxadi.txt");
- System.setOut(ps);
- System.out.println("iteye");
- ps.close();
PrintStream ps = new PrintStream("f://zzxadi.txt");
System.setOut(ps);
System.out.println("iteye");
ps.close();