刘政道 - 应用程序框架

《31天学会CRM项目开发(C#编程入门及项目实战)》作者,IT经理,程序员
  博客园  :: 新随笔  :: 联系 :: 管理

Java read a text file

Posted on 2010-01-28 16:42  刘政道  阅读(615)  评论(0编辑  收藏  举报
 1 
 2        public String mReadFileText(String path)
 3        {
 4           StringBuilder contents = new StringBuilder();
 5           try
 6           {
 7              BufferedReader input =  new BufferedReader(new FileReader(path));
 8              try
 9              {
10                   String line = null;
11                   while (( line = input.readLine()) != null){
12                      contents.append(line);
13                      contents.append(System.getProperty("line.separator"));
14                   }
15              }
16              finally {input.close();}
17           }catch(Exception ex){ex.printStackTrace();}
18           System.out.println("contents.toString():" + contents.toString());
19           return contents.toString();
20        }
21 
22