Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

altering random access file in java so it wont overwrite

  • 03-02-2006 08: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, Registered Users 2 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