Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •