用PrintStream向文件输入内容

Posted wei-jing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用PrintStream向文件输入内容相关的知识,希望对你有一定的参考价值。

 

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("很厉害的样子");
    }
}

 

结果

技术图片

 

以上是关于用PrintStream向文件输入内容的主要内容,如果未能解决你的问题,请参考以下文章