讀取文字檔
用FileReader類別讀取一個一個的char
import java.io.*;
public class MainWindow {
public static void main(String[] args) throws IOException {
FileReader fr=new FileReader("d:\\desktop\\test.txt");
int i;
while((i=fr.read()) != -1){
System.out.print((char)i);
}
}
}
用BufferedReader一次讀取一整行
import java.io.*;
public class MainWindow {
public static void main(String[] args) throws IOException {
FileReader fr=new FileReader("d:\\desktop\\test.txt");
BufferedReader br=new BufferedReader(fr);
String line;
while((line=br.readLine()) != null){
System.out.println(line);
}
}
}