I need to read bytes from a file.
Is there a difference (e.g. efficiency, memory, runtime, complexity and inelegance of code) between using RandomAccessFile
DataInputStream/DataOutputStream
is totally fine if you only need to read/write it sequentally.
If you need random access (like to an array of bytes) - use RandomAccessFile
.
I don't think there is any significant difference between them in terms of memory consumption etc. as they are just mediators between JVM and OS.
If you are only doing sequential access, by themselves they are essentially equivalent; however a DataInputStream
around a BufferedInputStream
around a FileInputStream
will be considerably more efficient than a RandomAccessFile
.