我想读取一个包含空格分隔值的文本文件。值是整数。我该如何阅读它?我想阅读每一行,然后转到下一个。
内容如示例:
“2012 年 12 月 11 日” “00.00.01” 0,100
“2012 年 12 月 11 日” “00.00.05” 0,140
“2012 年 12 月 11 日” “00.00.09” 0,240
“2012 年 12 月 11 日” “00.00.13” 0,247
第一列是日期,第二列是第二列,第三列是升。
我怎样才能用 Java 程序做到这一点?
我想使用 Scanner 类。我做了这个程序:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ScannerExample {
public static void main(String args[]) throws FileNotFoundException {
File text = new File("C:\Users\Desktop\test\test.txt");
Scanner scnr = new Scanner(text);
int lineNumber = 1;
while(scnr.hasNextLine()){
String line = scnr.nextLine();
System.out.println("line " + lineNumber + " :" + line);
lineNumber++;
}
}
}
但我没有我想要的结果。有什么帮助吗?