I am trying to make a program that stores a Username and Password for a user.
But i'm trying to have them re-edit the same file. So I want to read in the file re-write it then
add more information to it.
My only issue is that i would like to read in the text file and re-write it to keep the same formatting.
I have looked up different ways to rewrite it but they all end up rewriting the file in one line.
If anyone could offer any advice or help me it would be much appreciated.
Here is my code so far:
public static void main(String[] args) throws FileNotFoundException, IOException {
JFileChooser chooser;
//Lets user choose file.
chooser = new JFileChooser();
int result = chooser.showOpenDialog(null);
if (result != JFileChooser.APPROVE_OPTION)
return;
File info = chooser.getSelectedFile();
//Asks user to input new email address & password.
String email = JOptionPane.showInputDialog("Enter new e-mail address:");
String PW = JOptionPane.showInputDialog("Enter that e-mail's password:");
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(info));
out.write("------------------");
out.newLine();
out.write("E-mail: " + email);
out.newLine();
out.write("Password: " + PW);
out.newLine();
out.write("------------------");
out.close();
}catch(IOException e) {}
System.exit(0);
}
BTW i'm just using a text file.
Thanks in Advanced.