jeudi 3 juillet 2014

Appending to text file then displaying only certain fields


Vote count:

0




I'm making a savings calculator using netbeans with a JFrameForm. below is my working code to save to a .txt. for some reason when I click save it will not append to a new line and wont save at all. I would like to then load certain rows to an array and display in my text area. eg the savings field. First code for the save button, second block for the load button.



BufferedWriter writer = null;
try{
writer = new BufferedWriter(new FileWriter("C:\\test.txt"));
writer.write("\n" + date + "\t" + gross + "\t" + tax + "\t" + savings);
}
catch (Exception e){
JOptionPane.showMessageDialog(null, "Error saving");
}finally{
try{
//close the writer
writer.close();
}catch (Exception e){
JOptionPane.showMessageDialog(null, "Error closing save");
}
}



try{
FileReader reader = new FileReader("C:\\test.txt");
BufferedReader br = new BufferedReader(reader);
txaMain.read(br, null);
br.close();


}
catch(Exception E){
JOptionPane.showMessageDialog(null, "Error opening file");
}


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire