語法:
import java.io.*;
public class App {
public static void main(String[] args) throws Exception {
{
String file = "C:\\123.txt";
// 建立File物件
File name = new File(file);
if (name.exists()) {
// 建立BufferedReader的輸入串流物件
BufferedReader fr = new BufferedReader(new FileReader(name));
String str;
// 讀取資料
while ((str = fr.readLine()) != null) {
String[] s = str.split("\\s+");
for (int i = 0; i < s.length; i++)
System.out.print(s[i]+" ");
System.out.println();
}
fr.close(); // 關閉串流
} else
System.out.println("檔案[" + name + "不存在!");
}
}
}