【发布时间】:2017-05-07 20:24:15
【问题描述】:
我目前正在为我和我的朋友编写一个 Java 应用程序,但遇到了一个大问题...... 当我尝试读取 txt 文件时,它会打印带有奇怪字符的行,并且每个字符都用空格分隔。 我尝试使用不同文件夹中的多个 txt 文件,每次都打印相同的内容...(我尝试使用 Scanner 和 BufferedReader 制作代码,但仍然是同样的问题
这是我的代码:
BufferedReader br = new BufferedReader(new FileReader(_file));
String website = "";
String username = "";
String password = "";
int usedTimes = 0;
String currentLine;
while ((currentLine = br.readLine()) != null) {
if(currentLine.startsWith("Web Site")) website = currentLine.split(":")[1];
else if(currentLine.startsWith("User Name")) username = currentLine.split(":")[1];
else if(currentLine.startsWith("Password")) password = currentLine.split(":")[1];
else if(currentLine.startsWith("Password Use Count"))
{
usedTimes = Integer.parseInt(currentLine.split(":")[1]);
passwords.add(new Password(website, username, password, usedTimes));
website = "";
username = "";
password = "";
usedTimes = 0;
}
}
br.close();
这是一个示例输出:(我无法复制/粘贴输出,所以我放了一张图片)
所以如果你们中的任何人知道答案,请告诉我它会很棒!
非常感谢您在此之前阅读本文! 朱利安。
【问题讨论】:
-
您没有显示任何输出某些内容的代码。请告诉我们输出在哪里完成。
-
哦,是的,我刚刚添加了一个 system.out.println(currentLine);在while行下