Java如何讀取文本文件
來源:文萃谷 2.66W
Java具有簡單性、面向對象、分佈式、健壯性、安全性、平台的獨立與可移植性、多線程、動態性等特點。Java可以編寫桌面應用程序、Web應用程序、分佈式系統和嵌入式系統應用程序等。以下是小編為大家搜索整理的java如何讀取文本文件,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!
下面的代碼是讀取文本文件的'例子,程序會讀取文件,並將它的內容顯示出來。
1 import eredReader;
2 import ;
3 import Reader;
4 import NotFoundException;
5 import ception;
6
7 public class ReadTextFileExample
8 {
9 public static void main(String[] args)
10 {
11 File file = new File("");
12 StringBuffer contents = new StringBuffer();
13 BufferedReader reader = null;
14
15 try
16 {
17 reader = new BufferedReader(new FileReader(file));
18 String text = null;
19
20 // repeat until all lines is read
21 while ((text = Line()) != null)
22 {
23 nd(text)
24 nd(roperty(
25 "rator"));
26 }