繁体   English   中英

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

[英]how can one declare a word or number from a txt file into string

我正在编写一个程序来跟踪客户交流。 我正在尝试获取其中一位客户的 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; ^ 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;
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM