Java输出控制台信息到文件中

import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintStream; 

public class B {
    public static void main(String[] args)throws IOException {
        File f=new File("e://out.txt");
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PrintStream printStream = new PrintStream(fileOutputStream);
        System.setOut(printStream);
        System.out.println("默认输出到了文件 out.txt");
        

    }
}

猜你喜欢

转载自www.cnblogs.com/anningkang/p/11386632.html