Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: changing particular string in text file

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default changing particular string in text file

    I have a text file with this format:

    aaa:bbb:ccc
    ddd:eee:fff
    ggg:hhh:iii

    so now i want to search for fff and replace it with kkk but in same file. i know how to do by pasting stuff in other file. but for this i need that to be in same file

    any help will be appreciated

    Thanks


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: changing particular string in text file

    Just write in a separate file, delete the old and rename the new. Alternatively, read the file into memory, do the manipulation, then write to the file of the name of your choosing.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: changing particular string in text file

    I tried that b4 writing to memory but it didnt work for me.. what i want is not to change the file. let say i have this input.txt file i want the changes to occur in that particular file not in output.txt file ( file has to be same) . I have the code for coping one file to another when u make changes but, i want the file name to be same...

    any idea or do you have any example code

Similar Threads

  1. Reading in entire contents of text file to one string
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: December 12th, 2010, 07:03 PM
  2. Text File into String Array
    By mathanv in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2010, 05:30 AM
  3. reading string in from text file
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 3rd, 2010, 05:31 PM
  4. Reading lines of a text file into a string array
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 11th, 2010, 11:56 AM