------- android培训、java培训、期待与您交流! ----------
打印流:提供了打印方法,可以将各种数据类型的数据都原样打印。
字节打印流:PrintStream
构造函数可以接受的参数类型:
1.file对象File
2.字符串路径 String
3.字节输出流 OutputStream
构造函数可以接受的参数类型:
1.file对象 File
2.字符串路径 String
3.字节输出流 OutputStream
4.字符输出流 Writer
- import java.io.*;
- class PrintDemo
- {
- public static void main(String[] args)
- {
- BufferedReader bufr = null;
- PrintWriter out = null;
- try
- {
- bufr = new BufferedReader(new InputStreamReader(System.in));
- //true可以让out.println自动刷新。
- out = new PrintWriter(System.out,true);
- //可以把流写到文件中
- out = new PrintWriter(new BufferedWriter(new FileWriter("1.txt")),true);
- String line = null;
- while((line=bufr.readLine())!=null)
- {
- if("over".equals(line))
- break;
- out.println(line.toUpperCase());
- //out.flush();
- }
- }
- catch (IOException e)
- {
- }
- finally
- {
- try
- {
- if(bufr!=null)
- bufr.close();
- }
- catch (IOException e2)
- {
- }
- try
- {
- if(out!=null)
- out.close();
- }
- catch (Exception e1)
- {
- }
- }
- }
- }