A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 九天玄妖 中级黑马   /  2016-4-28 13:56  /  672 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

在PrintWriter这个类中,有构造方法,可以设置是否自动刷出,对这个自动刷出没有理解,
antoFlush这个参数给true的时候,不关闭流,也能写到文件中吗?测试是不关闭流是写不到文件中的。
还是我理解错了,请大家分享下经验。
PrintWriter(OutputStream out, boolean autoFlush)
通过现有的 OutputStream 创建新的 PrintWriter。

1 个回复

倒序浏览
  /**
     * Creates a new print stream.
     *
     * @param  out        The output stream to which values and objects will be
     *                    printed
     * @param  autoFlush  A boolean; if true, the output buffer will be flushed
     *                    whenever a byte array is written, one of the
     *                    <code>println</code> methods is invoked, or a newline
     *                    character or byte (<code>'\n'</code>) is written
     *
     * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
     */
    public PrintStream(OutputStream out, boolean autoFlush) {
        this(autoFlush, requireNonNull(out, "Null output stream"));
    }


PrintStream printStream = new PrintStream(new FileOutputStream("e:/123.txt"),true);
        printStream.println("123");

小伙子,来尝尝这个
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马