[20160731]read a file and print it on the screen

 1 //read a file and print it on the screen
 2 import java.io.*;
 3 
 4 public class MyPrintStreamTest2{
 5 public static void main(String[] args) {
 6 String filename = args[0];    // firsttime to see!!!
 7 if(filename!=null){ list(filename,System.out); }
 8 }
 9 
10 public static void list(String filename,PrintStream ps){
11 try
12 {
13 BufferedReader br = new BufferedReader( new FileReader(filename) );
14 String s = null;
15 while ((s=br.readLine())!=null) {
16 ps.println(s);
17 }
18 br.close();
19 }
20 
21 catch(IOException e)
22 {
23 ps.println("reading file error!");
24 }
25 
26 }
27 }

 

posted @ 2016-07-31 07:50  娃哈哈哈  阅读(116)  评论(0编辑  收藏  举报