---
title: "PrintWriter、PrintStream的苦头 ------缓冲区问题"
author: "holoblog"
date: "2011-10-29T12:40:00Z"
tags: []
slug: "printwriter-printstream"
draft: false
lastmod: "2011-11-20T20:08:52Z"
id: 1268535
url: "https://holoblog.iteye.com/blog/1268535"
---

由于PrintWriter的简便性，即只需要print()语句即可输出任何内容，因此用到这个类的次数非常多，但是我经常会忽视在构造方法中：new PrintWriter(new FileOutputStream(),**true**);

如果没有加这个true，后果非常匪夷所思。。。

不仅在文件流的操作，而且在网络编程Socket时，也会通过PrintWriter包装Socket的输出流，如果没有加true，则输出的东西不会在另一端取得；会抛出异常；

因此写这篇文章的目的是一定要记住缓冲区的问题，虽然我前面也写过一篇类似的文章；