Writer的子类,既可以接收字符流,也可以接收字节流,还可以接收文件名或者文件对象,非常方便

同时,还可以设置自动刷新以及保持原有格式写入各种文本类型的print方法

PrintWriter的小例子:打印字符录入的大写

//读取键盘录入,打印大写
throws IOException
   3: {
   4:     BufferedReader bufr =
new InputStreamReader(System.in));
   6:  
new PrintWriter(System.out,true);
   8:  
   9:     String line = null;
  10:  
while( (line = bufr.readLine()) != null)
  12:     {
.equals(line))
break;
//只需一条语句,便可打印一行数据,非常方便
  16:         out.println(line.toUpperCase());
  17:     }
  18:     
  19:     out.close();
  20:     bufr.close();
  21: }

相关文章: