我正在尝试让我的代码从文本文件中读取,并将其中的内容存储为变量..字符串和双精度字符...以备后用。我没问题让它返回信息。
.txt文件中的内容是
circle 5
triangle 3
square 10
sphere 5
cube 4
tetrahedron 8
对于我的代码,我有:
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(
"src/Data.txt"));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
// read next line
line = reader.readLine();
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}