码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-31 08:00:25      阅读:146      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!