So I am writing code that acts as a File System of sorts for a log in system two accounts are pre added, both being admins. they can create accounts. All accounts are stored in an array list for their username, and an array list for their password. I am trying to make it so that when i export this application, when an admin adds to the array list, is sends the information to a txt file, so that the next time the program is run, the program will load any accounts on the txt file. I have tested the loading of accounts, and that works fine, but i cannot seem to get to writing to a txt file. I picked up this code in this method from this site, but im not sure what I am doing wrong:
public static void writeFileContnet(){
String path = "C:\\Users\\DJANDEK\\Desktop\\LogInPro\\info.txt";
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(path, true));
if(!loadFileAsString(path).equals("")){
writer.newLine();
}
System.out.println(Account.accounts.get(Account.accounts.size()-1));
writer.write(Account.accounts.get(Account.accounts.size()-1));
System.out.println(breaker);
writer.write(breaker);
System.out.println(Account.passwords.get(Account.passwords.size()-1));
writer.write(Account.passwords.get(Account.passwords.size()-1));
writer.write(breaker);
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line;
try {
while((line = in.readLine()) != null)
{
System.out.println("it prints this");
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
just for those wondering about the println's, the console displays: Bob; 1Q2W; BobsPass (the info is correct). I get no errors in the console. To answer the duplicate question, He was told to use a file, not how to use the file. If I have data already on the txt file, the Reader will read and s.o.p it.