Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

altering random access file in java so it wont overwrite

Options
  • 03-02-2006 8:04pm
    #1
    Closed Accounts Posts: 201 ✭✭


    I am working with a file in java but I want to add in a couple of lines in the middle of it but when I do that it overwrites any lines that were previously there is there a way of preventing this. I would like to able to add in the lines in the middle and simply push down the lines that are below it in the file


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    create temp file.... copy first section into it.... write your own custom lines... copy remaining data into the temp file. Delete original, rename the temp file and you're done.


  • Closed Accounts Posts: 201 ✭✭bazcaz


    Ya cheers for the reply I actually got a fix for it just created a Vector and read the lines one at a time out of the file into the Vector then put then back into the file until I got to the point where I wanted to add my lines,added my lines then put the remaining lines out of the vector on the end of the file.


  • Registered Users Posts: 347 ✭✭Static


    bazcaz wrote:
    Ya cheers for the reply I actually got a fix for it just created a Vector and read the lines one at a time out of the file into the Vector ..

    Not the best approach if you're dealing with large files, you could end up gobbling all your available memory.


Advertisement