Basically, I am looking to add to a .txt file depending on whether a certain line exist already or not.
I.e. add the line to the .txt file if it doesn’t exist already.
Don’t add the line to the .txt file if it exists.
Every line stands alone
E.g.
One
Two
Three
and not
One, Two, Three etc.
I was thinking of using readLine() but it seems that it defines the end of a line when there’s a break, like there my lines have. The method doesn’t take any arguments (e.g. line numbers) so I’m pretty short-handen :/.
Any he
You can use, as you suggest, the readLine() method of RandomAccessFile to read each line of the file, looking for the expected text.
From the javadoc for readLine():
If the expected text is not found, then you can use one of the write methods of RandomAccessFile, e.g. writeUTF() or writeBytes() to add the line of text to the file.