aspose file tools*
The moose likes Beginning Java and the fly likes Replace Text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Replace Text" Watch "Replace Text" New topic
Author

Replace Text

Mudit Srivastava
Ranch Hand

Joined: Apr 30, 2007
Posts: 38
Hi All,

I have a text file which contains the following content

ABC=true
XYZ=true
DEF=false

I want to read from this file and check the property XYZ. If found true, I must replace with false. I am now unsure of how to delete the existing "true" value of XYZ from the file.

My current approach is as follows:



Kindly help since i have to create the entire file again using the ArrayList after clearing the entire content
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Mudit,

If your file is in format of key-value pair , you can use Properties API to acheive this.Note that Properties requires your file to be with .properties extn.

Use setProperty() method to change the proprty you want and then use Properties save method( on same loaded properties object) to save the properties to a file.

HTH


Mudit Srivastava
Ranch Hand

Joined: Apr 30, 2007
Posts: 38
Thanks for the post Balu.

Trouble is that I'm stuck with the .txt extension so I can't switch to the Properties API.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
The Properties class doesn't care about the file extension - it can be anything you want.


Ping & DNS - my free Android networking tools app
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


The Properties class doesn't care about the file extension - it can be anything you want.


yes , Thanks for the correction.
Mudit Srivastava
Ranch Hand

Joined: Apr 30, 2007
Posts: 38
Thanks guys. The Properties API worked like a charm..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Replace Text