java打印流总结

知识点:

 一:System类当中的方法: 
    System.in;  标准的输入流: 默认是键盘录入
    System.out; 标准的输出流: 默认是输出到控制台。 
  
    System.setIn(InputStream in); 改变来源。 
    System.setOut(PrintStream ps);  
    
    补充: 打印流:           
   PrintStream  构造器: 
   new PrintStream(String fileName);
   new PrintStream(OutputStream out); 
   
 二:   PrintStream: 打印流: 
  特点: 
   (1)能够打印基本数据类型的值。 
   (2)PrintStream 永远不会抛出 IOException;
   (3)写入 byte 数组之后自动调用 flush 方法。自动刷新。
   (4)println(); 提供了换行的方法。 
  构造器: 
    PrintStream(File file) 
          创建具有指定文件且不带自动行刷新的新打印流。 
    PrintStream(File file, String csn)  
  
   PrintStream(OutputStream out) ; 
   PrintStream(OutputStream out, boolean autoFlush) ;自动刷新。 
   PrintStream(String fileName) 
   
 //使用PrintStream类,将异常信息打印在外部文件当中。

 public static void main(String[] args) throws IOException {
        System.setIn(new FileInputStream("C:/Users/Mrzhang/javaEE/javaSE-07/javaSE-32/javaSE-32.txt"));
        System.setOut(new PrintStream("C:/Users/Mrzhang/javaEE/javaSE-07/javaSE-33/b.txt"));
        BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
        PrintStream ps = System.out;
        String line = null;

        while((line = bufr.readLine()) != null && !"over".equalsIgnoreCase(line)) {
            ps.println(line.toUpperCase());
        }

        bufr.close();
        ps.close();
    }
}

 上面的代码实现了指定的来源和目的。

2018年7月24日20:30:37于易动

猜你喜欢

转载自blog.csdn.net/qq_41517071/article/details/81191145
今日推荐