Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java file
how can i write string to a file , an update the file through my program?
(I want to write at the end of the text file each time)
Posted 14-Jan-13 4:53am
Coder93455
Comments
JasonMacD at 14-Jan-13 13:35pm
   
You do realize you posted this under C# right?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
ridoy at 14-Jan-13 11:59am
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
Try this:
FileWriter writer = new FileWriter("file.txt");
writer.write("Some text to append...");
writer.close();
If a file contains "This is text.", and if you execute this code, then your text file will contain this:
This is text.Some text to append...
If you want a new line after "This is text", then use the escape sequence for a new line:
FileWriter writer = new FileWriter("file.txt");
writer.write("\nSome text to append...");
writer.close();
In that case, your text file will contain this:
This is text.
Some text to append...
Hope this helps.
  Permalink  
v2
Comments
Coder93 at 14-Jan-13 14:41pm
   
If sometime I want to write at the end of the file and sometime i want to delete the
previous file and create a new one with same name what should i do?
ProgramFOX at 15-Jan-13 12:31pm
   
If you want to clear a file, and then writing, have a look here:
http://answers.yahoo.com/question/index?qid=20060906014353AAQBCn9

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 Sergey Alexandrovich Kryukov 170
4 PIEBALDconsult 160
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100