scanner 讀檔
package readFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
String path = "C:\\Downloads\\123.txt"; //檔案路徑
File f = new File(path); //得到檔案
Scanner sc =new Scanner(f);
while(sc.hasNext()){ //判斷有無資料
System.out.println(sc.next()); //有的話則顯示
}
}
}
留言
張貼留言