要实现的是:把本来在console里输出的运算结果,输出到桌面,保存到results.txt文件中。完成以后,在console中输出“你的文件已被保存到桌面!”下面是我现在的代码,比较笨,欢迎高手指教:
public static void main(String args[]) throws IOException { FileSystemView fsv = FileSystemView.getFileSystemView(); File desktop = fsv.getHomeDirectory(); String deskPath = desktop.getPath() + "\\results.txt"; File outputFile = new File(deskPath); PrintStream ps = new PrintStream(new FileOutputStream(deskPath));
System.setOut(ps);
System.setErr(ps);
doTheWholeTest(5,20,5); // 打印结果的方法 System.out.println("Your results have been printed on your desktop: "
+ outputFile.getPath()); //关键就是这句,怎么在文件保存后输出在console里
}}
按照以上代码,最后一句话被输出在txt文件里了,请问怎么让它输出在console里呢?谢谢!