我使用一个按钮来保存用户输入到一个文本文件,现在我想检索它来做一个计算。 正在更新文本文件并添加新值。 下面是一个例如文本文件的样子:Java:如何从文本文件中只读取int数据来执行计算?
- 周一:周二1:2 wednessday:3
...等
当有一个新的输入它将被添加,所以 更新的文本文件看起来像这样:
- 周一:1星期二:2 wednessday:3
- 星期一:4星期二:1个wednessday:3
- 星期一:6星期二:5 wednessday:6
- 星期一:7周二:6 wednessday:5
基本上我想比较新的输入和以前的输入。 如何从最新和最后输入中只检索所有整数?
还是应该用excel?
这里是我的代码:
try (
InputStream fs = new FileInputStream("data.txt");
// not sure how to use the Charset.forname
InputStreamReader isr = new InputStreamReader(fs, Charset.forName("UTF-8"));
BufferedReader br = new BufferedReader(isr)) {
for (String line1 = br.readLine(); line1 != null; line = br.readLine()) {
comp = line1 - line2; //line1 being current line(4) and line2 being the previous(3)
}
}
你确定你粘贴的代码是正确的吗? –
“最新”的标准是什么? –
@TimothyTruckle最新是第4行,最后是第3行 –