如何将txt文件中的单词或数字声明为字符串



我正在编写一个程序来跟踪客户交流。我试图在一个客户的txt文件中获取该数字,并将该数字声明为字符串以便使用。例如,将其添加到另一个数字中。我试过做不同的事情,比如把它读为最后一行,但我发现错误,找不到符号。请帮帮我,我对java还很陌生,正在尽可能多地学习。

谢谢你,这是我试过的密码。

FileInputStream in = new FileInputStream(acc+".txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = null, tmp;
while ((tmp = br.readLine()) != null) {
strLine = tmp;
}
String lastLine = strLine;

所以我试着使用最后一行,但它说找不到符号,我不知道该怎么做

这是错误:cannot find symbol int we=lastline-o; ^

您可以用这种方法读取文件,使用当前换行保留最后一步的最后一行

FileInputStream in = new FileInputStream(acc+".txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String currentLine, lastLine, tmp;
while ((tmp = br.readLine()) != null) {
// read new line
currentLine = tmp;
// do your logic
lastLine + currentLine;
// update last line for next iteratino
lastLine = currentLine;
}

最新更新