Results 1 to 2 of 2
Thread: File overwriting?
- 02-08-2012, 09:08 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 25
- Rep Power
- 0
File overwriting?
Basically I am trying to save to a csv file however it keeps overwriting my previous file, while instead I would like it to add to the end of the file. Here is my code :
Can you see what is wrong with it?Java Code:String generateCSVFile = "test.csv"; File f; f = new File("test.csv"); if(!f.exists()){ try { f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("New file \"test.csv\" has been created to the current directory"); } try { FileWriter writer = new FileWriter(generateCSVFile); BufferedWriter out = new BufferedWriter(writer); out.append(UsernameTxt.getText()); out.append(','); out.append(PasswordFld.getText()); out.append('\n'); out.flush(); out.close(); NLbl.setText("File saved"); } catch(IOException e) { e.printStackTrace(); } }
- 02-08-2012, 09:11 PM #2
Member
- Join Date
- Feb 2012
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
Writing data to file, but not overwriting it.
By Renxx in forum New To JavaReplies: 3Last Post: 12-10-2011, 10:14 PM -
Hibernate adding/overwriting records incorrectly
By jhasell in forum JDBCReplies: 8Last Post: 07-05-2011, 06:32 PM -
Array overwriting data
By hobo in forum New To JavaReplies: 7Last Post: 10-27-2010, 01:29 PM -
Overwriting add() to make an own subclass of JDialog
By flobo in forum AWT / SwingReplies: 0Last Post: 03-05-2010, 07:11 PM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks