So, I'm still new to programming and this site. I've been trying to make my own browser just for fun and I'm learning how to write and read from text files to use as logs to save data. I'm trying to make a Favorites system so that I can save different websites to a log but I can't understand why part of my code isn't working. I've spent about two and a half hours on the web looking around and I can't see any issues.
try(BufferedReader format1 = new BufferedReader(new
FileReader("favorites.txt"))) {
String line = format1.readLine(); //Used to look through file
String found = ""; //Stores the address that was the same
//Loop searches file, I only plan to have a max of 20 favorites
for (int counter = 0; counter < 20; counter++) {
System.out.println(line); //Just used so I can make sure the
loop works
if(line.equals(input)) {
counter = 20;
found = line;
}
line = format1.readLine();
}
format1.close();
if(!(found.equals(input))) {
BufferedWriter format2 = new BufferedWriter(new
FileWriter("favorites.txt", true));
format2.write(input);
format2.newLine();
format2.close();
}
} catch (IOException e1) {
System.out.println("ERROR! Favorite not Added.");
}
I've checked to see where the problem lies and the if statement that actually writes to the file seems to be where the problem is. I've looked a million times and I can't see anything. Maybe a more experienced programmer could see my issue? Whenever I run this section of code, it spits out a ton of error messages. I appreciate any help!