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: java: performing modification in file.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default java: performing modification in file.

    Hi,

    I have a file like file1.txt. It contain more than 1000 lines. My requirement is to perform the modification in 15th line of file1.txt.

    But i know the code like to read the all lines form file1.txt and performing the modification in 15 th line and store the modification content in another file like fil2.txt. My requirement is just perform the modification only one word in 15th line, but the above logic take so much time to read and write the content .


    Please share is there any another bettor logic to change the content in file ?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: java: performing modification in file.

    Normally with a text file, to modify part of it, all of it must be read and written, unless the modification fits exactly over the existing data then the modification could be done by writing over the bytes to be modified.
    For example if the mod was to change three bytes at location 250, then the bytes at 250, 251 and 252 could be written to with the new data. The RandomAccessFile could be used for that.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: java: performing modification in file.

    Thank you Norm

Similar Threads

  1. modification to core java file: javax.script.AbstractScriptEngine
    By amughost in forum Java Theory & Questions
    Replies: 0
    Last Post: June 13th, 2012, 11:37 AM
  2. Replies: 4
    Last Post: January 7th, 2012, 01:59 PM
  3. Replies: 1
    Last Post: January 6th, 2012, 07:02 AM
  4. Polynomial LinkedList from Text File (Modification)
    By javaNewb37 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 27th, 2011, 02:05 AM
  5. Problem understanding Java code modification
    By eagle09 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 26th, 2011, 04:13 PM