我無法從簡單的文本文件中讀取,也無法找出原因。我之前做過這件事,而且我不確定問題是什麼。任何幫助,將不勝感激!從文件讀取 - 錯誤的文件類型?
import java.io.File;
import java.util.Scanner;
public class CS2110TokenReader {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File theFile = new File("data1.txt");
Scanner scnFile = new Scanner(theFile);
try {
scnFile = new Scanner(theFile);
} catch (Exception e) {
System.exit(1);
}
while (theFile.hasNext()) {
String s1 = theFile.next();
Double d1 = theFile.nextDouble();
System.out.println(s1 + " " + d1);
}
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method hasNext() is undefined for the type File
The method next() is undefined for the type File
The method nextDouble() is undefined for the type File
at CS2110TokenReader.main(CS2110TokenReader.java:20)
它甚至不會掃描下一行。這是我的目標。掃描和閱讀。
什麼是錯誤/輸出?你期望會發生什麼? –
已更新以上信息 – Evorlor