Click here to Skip to main content
11,643,493 members (69,175 online)
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 3:53am
Coder93463
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 570
1 jyo.net 484
2 DamithSL 318
3 Afzaal Ahmad Zeeshan 253
4 CPallini 222
0 OriginalGriff 795
1 DamithSL 611
2 Mika Wendelius 494
3 jyo.net 484
4 Afzaal Ahmad Zeeshan 404


Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2015
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