- 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();
- }
- }
复制代码
|