A
Andreas Leitgeb
As far as I understood the tutorials and documentation, then the java.io.*
classes have been redesigned (already back in the Java 1.4 days) to work
on the nio-API as its lower level.
From this, it's not surprising, that RandomAccessFile has a method to
get access to the nio FileChannel and is mostly some convenience class
that (among other things) allows reading single lines, and then have the
current fileposition right after the newline of that read line.
Unfortunately, however, the RandomAccessFile still has only constructors
taking the open-mode as a String (with only "r","rw","rws","rwd" being the
legal values).
If instead I open a FileChannel using the nio API, then I can specify POSIX
flags, like TRUNCATE or APPEND.
What I'm missing is a way to wrap a RandomAccessFile over an existing
FileChannel, such that I can use the more flexible open modes, but
still get a convenient readLine().
Btw., I'd really like a readLine() for reading lines also from Channels
that are not FileChannel, but perhaps Pipe.SourceChannel or sockets.
And just one more thing: I've seen that I can wrap streams like System.out
in a Channel, using Channels.newChannel(System.out), but I don't know how
I could undo this wrapping, eventually getting rid of the wrapping Channel
without having System.out closed as a side effect. I'm a bit scared that
merely "forgetting" the Channel might eventually cause it to be close()d
from its finalizer.
classes have been redesigned (already back in the Java 1.4 days) to work
on the nio-API as its lower level.
From this, it's not surprising, that RandomAccessFile has a method to
get access to the nio FileChannel and is mostly some convenience class
that (among other things) allows reading single lines, and then have the
current fileposition right after the newline of that read line.
Unfortunately, however, the RandomAccessFile still has only constructors
taking the open-mode as a String (with only "r","rw","rws","rwd" being the
legal values).
If instead I open a FileChannel using the nio API, then I can specify POSIX
flags, like TRUNCATE or APPEND.
What I'm missing is a way to wrap a RandomAccessFile over an existing
FileChannel, such that I can use the more flexible open modes, but
still get a convenient readLine().
Btw., I'd really like a readLine() for reading lines also from Channels
that are not FileChannel, but perhaps Pipe.SourceChannel or sockets.
And just one more thing: I've seen that I can wrap streams like System.out
in a Channel, using Channels.newChannel(System.out), but I don't know how
I could undo this wrapping, eventually getting rid of the wrapping Channel
without having System.out closed as a side effect. I'm a bit scared that
merely "forgetting" the Channel might eventually cause it to be close()d
from its finalizer.