Have you seen the Java™ Tutorials section about NIO?
Please explain how these data are stored. Are they received as some sort of input stream, or are they written directly to a file? Does your input write them sequentially into your file?
If you're asking how to store a stack in a file, you can do this easily by keeping the offset of the last entry in the file header, and in every entry keep the offset of the previous entry.
Stephan: wouldn't a stack be LIFO/FILO and OP asked for FIFO?
Presumably you can write successive lines to a file and read them in order. But that produces a race condition, so it wouldn't be thread‑safe. It might also not be possible to open a file for reading and writing simultaneously.
Ahhh yes. For some reason I read LIFO and I just went with it.
FIFO is indeed just writing the entries one after the other. I have no idea why one would want to read and write at the same time, maybe OP can share more details about their use case with us.