Results 1 to 2 of 2
- 07-09-2007, 04:56 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
Problem with storing and retrieving from a textfile
I used these lines of code for getting data from text field and storing into a textfile.
But this overwrites into same place, all i want to do is storing more than one data in a same file.
Also I could not retrieve data from a text file using BufferedReader method.
Greetings.Java Code://try { BufferedWriter fileOut = new BufferedWriter(new FileWriter("filename.txt")); //Create the Buffered Writer object to write to a file called filename.txt fileOut.write(myTextField.getText()); // Write to the file, using the text from our textfield fileOut.close(); // Close the output stream after all output is done. } catch (IOException ioe) { ioe.printStackTrace(); //}
Albert:rolleyes:
- 07-13-2007, 03:01 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 44
- Rep Power
- 0
You'll probably want to use .append(char c) rather than .write()
Writer (Java 2 Platform SE 5.0)
BufferedWriter (Java 2 Platform SE 5.0)
Another way (besides what Gox has written) is when you create the new FileWriter is to add a boolean of true for appending.
That will always append to the end when you do stdout.write("something");Java Code:import java.io.*; public class test { public static void main (String args[]) throws IOException { BufferedWriter stdout = new BufferedWriter(new FileWriter("file.txt", true)); } }
FileWriter (Java 2 Platform SE 5.0)
Similar Threads
-
ECG plot in a textfile
By samson in forum Java 2DReplies: 13Last Post: 01-28-2012, 04:02 PM -
Search TextFile
By gsupriyarao@yahoo.com in forum Advanced JavaReplies: 5Last Post: 04-11-2008, 11:03 AM -
storing and retrieving a file as such
By anil_manu in forum Advanced JavaReplies: 0Last Post: 03-11-2008, 01:27 PM -
reading textfile from java problem
By saytri in forum New To JavaReplies: 1Last Post: 01-17-2008, 02:13 AM -
Storing Data
By Khorod in forum New To JavaReplies: 1Last Post: 08-03-2007, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks