Results 1 to 3 of 3
Thread: Saving to a Text File
- 10-17-2008, 03:04 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 12
- Rep Power
- 0
Saving to a Text File
What is the Code if yur trying to save and want to save to the same text [B]WITHOUT replacing the existing text. Instead the next goes to next line.
here the code Im using:
if(event.getSource() == signupButton) {
try {
outFile1 = new PrintWriter ( new BufferedWriter( new FileWriter("register.txt")));
outFile1.print(usernameField.getText()+", ");
outFile1.print(password.getText()+", ");
outFile1.close();
JOptionPane.showMessageDialog(null,"Data have been Saved");
}
- 10-17-2008, 03:11 PM #2
If you want to "APPEND" your text to the end of an existing file, read the API doc for the file class and look for an arg that says to append to that file.
- 10-17-2008, 06:50 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Read more about FileWriter class on the API.
I wonder why are you using such an annoying way to write data to a file. Seems to me you no need to use PrintWriter instance there.Java Code:outFile1 = new PrintWriter ( new BufferedWriter( new FileWriter("register.txt", true)));
Similar Threads
-
[SOLVED] jfilechooser for saving a file....?
By prabhurangan in forum AWT / SwingReplies: 9Last Post: 03-19-2012, 05:20 PM -
Saving and updating a single file
By AkisV in forum Advanced JavaReplies: 1Last Post: 09-27-2008, 02:42 PM -
find and replace text from a text file
By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM -
Saving data in an XML file
By Thez in forum New To JavaReplies: 1Last Post: 12-08-2007, 09:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks