0
点赞
收藏
分享

微信扫一扫

PrintStream与PrintWriter

树下的老石头 2022-03-11 阅读 15

PrintStream

package com.qiu.print;

import java.io.IOException;
import java.io.PrintStream;
//打印流只有输入流,没有输出流
public class PrintStreamDemo1 {

    public static void main(String[] args) throws IOException {
        PrintStream pri=System.out;
        System.setOut(new PrintStream("F:\\IDEA(java)\\IO流\\IO流文件\\new8.txt"));
        System.out.println("蒙奇.D.路飞,是要成为海贼王的男人");
        System.out.println("你好");
        System.out.println("漩涡鸣人");
        pri.println("控制台输出");
    }
}

PrintWriter

package com.qiu.print;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class PrintWriterDemo1 {
    public static void main(String[] args) throws IOException {
        PrintWriter printWriter = new PrintWriter(new FileWriter("F:\\IDEA(java)\\IO流\\IO流文件\\new9.txt"));
        printWriter.println("你好呀,写入数据成功");
        printWriter.close();//其实close方法里面才会写入数据
    }

}
举报

相关推荐

0 条评论