成都创新互联网站制作重庆分公司

java_io_打印流,PrintStream和PrintWriter-创新互联

*PrintStream和PrintWriter,效果相似

成都创新互联公司专业提供西部信息机房服务,为用户提供五星数据中心、电信、双线接入解决方案,用户可自行在线购买西部信息机房服务,并享受7*24小时金牌售后服务。
  • 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();

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:java_io_打印流,PrintStream和PrintWriter-创新互联
URL标题:http://cxhlcq.com/article/geghs.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部