Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Find and replace a word in a file using java

Thread view: 
rynox - 17 Nov 2005 06:13 GMT
Hi Everyone,

My situation is I have a .jsp file which i want to edit a value. Can
java read the file, search for the particular word and then modify that
word into another value ? Any links to read on this or example.

Thanks.
Roedy Green - 17 Nov 2005 06:22 GMT
>My situation is I have a .jsp file which i want to edit a value. Can
>java read the file, search for the particular word and then modify that
>word into another value ? Any links to read on this or example.

You are trying to modify your source code on the fly?

Read the file as one  great string. You can read it in a single
unbuffered i/o. See http://mindprod.com/jgloss/fileio.html
for how.

Now you indexOf to find the word.  Now write out the prefix. write the
word, write the suffix.

that saves creating a giant StringBuffer/String
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Rhino - 17 Nov 2005 14:20 GMT
> Hi Everyone,
>
> My situation is I have a .jsp file which i want to edit a value. Can
> java read the file, search for the particular word and then modify that
> word into another value ? Any links to read on this or example.

Sounds like an awful lot of work to me! Wouldn't it make more sense to use
your text editor or IDE to alter your JSP source?

Rhino
charles_n_may@yahoo.com - 17 Nov 2005 15:17 GMT
Can you alter your JSP to read the value on the fly from a properties
file, or some dynamic value from the HttpRequest? Alternatively, how
about changing the jsp during your build process using an Ant <replace>
or <replaceregexp> task?

> Hi Everyone,
>
[quoted text clipped - 3 lines]
>
> Thanks.
Malte - 18 Nov 2005 15:28 GMT
> Hi Everyone,
>
[quoted text clipped - 3 lines]
>
> Thanks.

Combination of awk/sed should get you going.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.