Posted on 2009-06-29 19:28
周競先 閱讀(115)
評論(0) 編輯 收藏 所屬分類:
J2SE
1
2 /**
3 * 讀取指定文件的內容
4 * @param fileurl 要解析的html文件
5 * @return
6 */
7 public String getContent(String fileurl){
8
9 //讀寫文件流
10 BufferedReader in;
11
12 String line, contentString = new String();
13
14 try {
15 in = new BufferedReader(new FileReader(fileurl));
16
17 while((line = in.readLine()) != null)
18 contentString += line.trim();
19
20 //關閉流
21 in.close();
22
23 //測試數據打印
24 System.out.println("文件內容:\n"+contentString);
25
26 } catch (FileNotFoundException e) {
27
28 e.printStackTrace();
29 } catch (IOException e) {
30
31 e.printStackTrace();
32 }
33
34 return contentString;
35 }
最后出來的文件內容是一個去掉了空格的字符串
Life,simple and happy!