温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java _io_打印流,PrintStream和PrintWriter

发布时间:2020-07-30 19:23:40 来源:网络 阅读:395 作者:wx5d21d5e6e5ab1 栏目:编程语言

*PrintStream和PrintWriter,效果相似

  • PrintStream ps=new PrintStream(字节流,true/false),为真则自动刷新内容,默认为假
  • System.out默认为PrintStream 打印流
  • 写入文件(通过.println):
  • PrintStream ps=new printStream(new BufferedStream(FileOutputStream("vv.txt")),true)
  • ps.println("ad")
  • 重定向输出端(输出到文件):System.setOut(ps); ps.println("aa");
  • 重定向回控制台:System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));

PrintStream:

        //打印流System.out
        PrintStream os =System.out;
        os.println("haha");

    //写入文件
    os= new PrintStream(new BufferedOutputStream(new FileOutputStream("vv.txt")),true);
    os.println("add");
    os.println(false);
    os.flush();
    os.close()

    //重定向输出端(输出到文件)
    System.setOut(os);
    System.out.println("change");

    //重定向回控制台
    System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));
    //标准的输入输出端

PrintWriter:

    PrintWriter pw=new PrintWriter(new BufferedOutputStream(new FileOutputStream("vv.txt")),true);
    pw.println("ff");
    pw.println(true);
    pw.close();
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI