Posted on 2009-06-29 19:28
周競(jìng)先 閱讀(114)
評(píng)論(0) 編輯 收藏 所屬分類:
J2SE
1
2 /**
3 * 讀取指定文件的內(nèi)容
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 //關(guān)閉流
21 in.close();
22
23 //測(cè)試數(shù)據(jù)打印
24 System.out.println("文件內(nèi)容:\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 }
最后出來的文件內(nèi)容是一個(gè)去掉了空格的字符串
Life,simple and happy!