首页 > 其他 > 详细

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

时间:2016-07-31 07:58:56      阅读:273      评论:0      收藏:0      [点我收藏+]
 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 }

 

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

原文:http://www.cnblogs.com/jasonzeng888/p/5722307.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!