I am currently codding a Java application for me and my friends and I am encoutering a big problem... When I try to read a txt file, it prints the lines with strange caracters and each caracter is separed by a white space. I tryed with multiple txt files in different folders and I prints the same thing everytime... (I tryed to make the code with a Scanner and a BufferedReader and it is still the same problem
Here is my code:
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();
Here is an example output: (I cant copy/paste the output so I place a picture)
So if anyone of you knows the answer, please tell me it would be great !
Thank you really much for reading this until here ! Julien.
It may be encoding issue. You have to check text file encoding, and then you have to try like this: BufferedReader r = new BufferedReader(new InputStreamReader("ISO-XXXXX"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.