I have a text file where I want to change only the first line of the file. The file could be millions of rows long, so I\'d rather not have to loop over everything, so I\'m
If the new line has a different amount of characters (bytes) than the original first line, you will have to re-write the whole file to get rid of the gap or avoid overwriting part of the second line.
Of course, various tools like String.replaceFirst(String regex, String replacement) (javadoc) or the RandomAccessFile (javadoc) can help you with this task.