黑马程序员技术交流社区
标题:
IO流之打印流的总结
[打印本页]
作者:
mengxiang1993
时间:
2015-2-26 11:15
标题:
IO流之打印流的总结
package day20;
import java.io.*;
/**
* 字节打印流:PrintStream
* 构造函数可接受的参数:
* 1.File对象 :File
* 2.字符串路径 :String
* 3.字节输出流:OutputStream
*
* 字符打印流:PrintWriter
* 1.File对象:File
* 2.字符串路径:String
* 3.字节输出流:OutputStream
* 4.字符输出流:Writer
*
* 需求:接受控制台的字符串,并将小写转换成大写,输出在控制台或文件
* 步骤: 1.BufferedReader 接收控制台字符 2.PrintWriter写入到控制台
*
* 重点:
* 1.FileWriter(File f,boolean b)和FileOutputStream(File f,boolean b)带有追加文件的功能
* 2.PrintWriter 和 PrintOutputStream 都有自动刷新缓冲区的功能
*
*/
public class PrintDemo {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter out = new PrintWriter(System.out, true);
PrintWriter out=new PrintWriter(new FileWriter("p.txt",true),true);
String line = null;
while ((line = br.readLine()) != null) {
if (line.equals("over"))
break;
out.println(line.toUpperCase());
}
br.close();
out.close();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2