【发布时间】:2013-06-12 20:38:39
【问题描述】:
我不明白如何从下面的.txt 文件中读取数据。
static final String DATA_PATH = "DataFile.txt";
public static void main(String[] args) {
Scanner fileReader = null;
try {
fileReader = new Scanner(new File(DATA_PATH));
//Print out a trace of the program as it is running
System.out.println("Debug: Scanner is open "+fileReader);
} catch (FileNotFoundException e) {
// If the file is not there, an exception will be thrown and the program flow
// will directed here. An error message is displayed and the program stops.
System.out.println("The file "+DATA_PATH+" was not found!");
System.out.println("The program terminates now.");
System.exit(0);
}
【问题讨论】:
-
真的吗?你甚至保留了练习号
-
你的冒险精神在哪里? :) 查看
Scanner类的文档(网络|| 教科书),即使键入带有句点的变量,如fileReader.,也应该打开IntelliSense 并给你一些想法。 (我不会去-1,因为你刚刚开始stackoverflow)
标签: java.util.scanner filereader