Results 1 to 4 of 4
Thread: Appending to a file to write to
- 07-20-2011, 01:27 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
Appending to a file to write to
Hi everyone, I am new to input/output streaming, and I just want to know how to append to a file.
Here is my code:
Java Code:s = "this is my text" public static void main(String[] args) throws IOException { PrintWriter outputStream = null; try { outputStream = new PrintWriter(new FileWriter("output.txt")); outputStream.println(s); } finally { if (outputStream != null) { outputStream.close(); } } }
It does write to the output, but when I change the value of s and rerun the program, it just erases what was there before and writes on top of it. Is there a separate command for appending to a file and will it start on a new line?
also, how would I indicate the path, right now it just puts it in my project folder.
Thanks
- 07-20-2011, 01:43 AM #2
The FileWriter class has more than one constructor!
- 07-20-2011, 01:58 AM #3
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
Alright, that was perfect and solved my one problem.
Now I'm just curious how to change the path of output.txt
- 07-20-2011, 02:01 AM #4
Similar Threads
-
problem with appending to file
By Ninjateckie in forum Java AppletsReplies: 0Last Post: 03-14-2011, 08:32 PM -
Appending WAV file at the end of an existing file
By phil128 in forum New To JavaReplies: 2Last Post: 12-11-2010, 11:20 PM -
Write a program that sorts data from a text file and sort them in a file
By danmgz45 in forum New To JavaReplies: 6Last Post: 12-01-2010, 05:31 AM -
how to change the layout of an input file and write to an output file
By renu in forum New To JavaReplies: 8Last Post: 05-12-2010, 07:19 PM -
Appending to a File Used for Serialization
By Lil_Aziz1 in forum Advanced JavaReplies: 8Last Post: 02-02-2010, 10:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks