import java.io.*;
import java.util.Scanner;
public class FileIOBufferReader {
public static void main(String[] args) {
try {
String fileName, fileDir;
System.out.println("請輸入檔名: ");
Scanner sn = new Scanner(System.in);
fileDir = sn.next();
FileReader file = new FileReader(fileDir);
BufferedReader bf = new BufferedReader(file);
do {
String data = bf.readLine();
if (data == null)
break;
System.out.println(data);
} while (true);
bf.close();
} catch (IOException e){
System.out.println("輸入檔案路徑錯誤");
}
}
}
執行結果
沒有留言:
張貼留言