import java.io.*; public class Main { public static void main(String[] args) throws FileNotFoundException { PrintStream ps = new PrintStream(new FileOutputStream("work.txt")); //改变输出流,输出到work.txt文件 System.setOut(ps); //用System.out.println()即可将内容输出到文件中 System.out.println(12); double d = 2.36; System.out.println(d); System.out.print("可以吗"); System.out.println("很厉害的样子"); } }
结果