• Post Reply Bookmark Topic Watch Topic
  • New Topic

append the text in a file  RSS feed

 
mohanasundaram muthukannan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
i want one program solve the following data

i have a.txt file

that file content is




i want insert the word <listvalue>NON-TEACHING STAFF</listvalue> after <listvalue>TEACHING STAFF</listvalue> this word.

please help me.

Thanks
Mohan.M




 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to manipulate files, look into the API java.io.RandomAccessFile. This class allows you to read and write data.

Another simpler approach may be to use the java.util.Properties load and store methods. Load just read the file into a Properties object. You then set property to add stuff. Then store to write the entire object back to the file. But in your case the RandomAccessFile may be the one you want to use.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RandomAccessFile is a bad option if you want to add or remove data from the file, or replace data with a different size. Properties also seems like a non-viable solution; the Properties format is completely different.

If the new tag would need to be placed at the end, simply using the FileWriter constructor that takes a boolean would suffice. Now you'll have to read the entire file first, parse it, add the element in between and then write it to the file again. You can use the JDOM library among others for this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!