Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-11-2011, 12:48 AM   PM User | #1
zverys36
New to the CF scene

 
Join Date: May 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
zverys36 is an unknown quantity at this point
Reading/writing file

Hello, what I want to do in Java is to read a text file (I already have a method how to read a file, so that's not the concern) and WHEN a certain word is read (such as D), I want to replace that character with a number "4". Can you provide some information as to how to achieve this? Possibly some sample code? Thanks in advance!
zverys36 is offline   Reply With Quote
Old 05-17-2011, 02:36 PM   PM User | #2
micky7s
New to the CF scene

 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
micky7s is an unknown quantity at this point
Hi,

In brief what you need is :

1. Read every line from file
2. Use String class. There are methods (replace, replaceAll, replaceFirst) Use these methods and replace what you need
You'll have to use regular expression

Check this on regular expressions:
http://download.oracle.com/javase/tu...sential/regex/
micky7s is offline   Reply With Quote
Reply

Bookmarks

Tags
java, read, read/write, replace, write

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:41 PM.


Advertisement
Log in to turn off these ads.