将控制台信息输出到文件

xiaoxiao2021-02-28  8

import java.io.*; public class IO2File { public static void main(String[] args) throws IOException { File f=new File("out.txt"); f.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(f); PrintStream printStream = new PrintStream(fileOutputStream); System.setOut(printStream); System.out.println("默认输出到控制台的这一句,输出到了文件 out.txt"); } }
转载请注明原文地址: https://www.6miu.com/read-2400155.html

最新回复(0)