Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a ~ at the end of the line  RSS feed

 
Bharath Sundar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a text file, i have to add a '~' at the end of each line in the text file. Can anyone help me in this.

Thanks.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Read the file a line at a time.
2) Write each line with the '~' appended to a new file.
3) If 1) and 2) work OK then rename the original file to a temporary name.
4) Rename the new file to the name of the original file.
5) If all the above work OK then delete the original file (that now has a temporary name).

Points to note -

a) Make sure you use the correct character encoding.
b) Make sure you close the files in a finally clause after reading and writing or you won't be able to rename or delete.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!