aspose file tools*
The moose likes I/O and Streams and the fly likes clear the text then add new text to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "clear the text then add new text to file" Watch "clear the text then add new text to file" New topic
Author

clear the text then add new text to file

Aya Muhannad
Greenhorn

Joined: Dec 14, 2013
Posts: 22
Hello;
I have a code that clear old text then add new text to text file afterthat download the file
but the problem my code dose not add new text


plz help me to clear old text then add new text to text file
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2596
    
    9

If you want to "clear old text then add new text to text file" then isn't that the same as overwriting the file with the new text? If so why need to clear old text?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2366
    
  50
Your FileWriter should probably be writing to the file denoted by 'filename' and not by 'name' and as K. Tsang has said there is no need to clear old text, just remove the 'true' parameter from the FileWriter constructor to overwrite the file with the new data.
Aya Muhannad
Greenhorn

Joined: Dec 14, 2013
Posts: 22
I put the filename parameter to FileWriter but the new text is not written in a file
and I want to replace the old text with new text
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2366
    
  50
Can you post the code you are now running
Aya Muhannad
Greenhorn

Joined: Dec 14, 2013
Posts: 22
I solved that prblem by this code
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2366
    
  50
Glad to hear you have it working and thanks for updating the thread with the solution
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: clear the text then add new text to file