Basically, what I'm doing is writing to a file and then reading it later. A few times I was looking at the buffer, and seeing lines 'cut off,' and getting concerned it was a flushing issue. However, I stumbled across this question, which states:
So, it appears scanner does not read the entire file at once...it reads file by buffer - which means in chunks.
and I see that reflected in my scanner. Looking at the buffer size, I see 1024 as the size.
However! I was writing each entry as a separate line, passing in the message and appending \n
to it before writing. Taking that \n
away then results in something interesting. When running without the newlines, I find that the buffer size has magically increased to something interesting like 5,232, and I can now see the entire contents of the file in the buffer!
The way I make the Scanner is simply a new Scanner(new FileInputStream("path.txt"))
, and then inspect it using Intellij's variable inspection (that's where I got the idea of cutting off from, I wasn't able to see everything in the file)
Essentially, my question is: why does adding the newlines force the buffer to be a fixed size and obey the rules, and not adding newlines (meaning the entire file is just one line) lets the buffer be whatever size it needs to be?