溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java _io_打印流,PrintStream和PrintWriter

發布時間:2020-07-30 19:23:40 來源:網絡 閱讀:702 作者: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

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女