0

I have a textfile where the text inside looks like this:

    first line : some content
    second line: some content
    third line : some content
    fourth line: some content

I want to add "some content" between the 2cnd and third line, but with

    out.println(somecontent)

it writes in front of the file. Another point is that I sometimes need to change the firstline-content with the thirdline-content. Is it the best solution to create a second file or to save it temporary in strings? And how do i get my program to write the string between the other files?

Yannic Hansen
  • 235
  • 3
  • 17

1 Answers1

0

If the file is small, read it and perform the modifications in-memory and then write back to disk; If it is too big for that, read a block of data and write back the new block using this method.

Community
  • 1
  • 1
AlexR
  • 2,412
  • 16
  • 26