Java RandomAccessFile vs. DataInputStream for byte operations

后端 未结 2 1210
你的背包
你的背包 2020-12-21 13:54

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

2条回答
  •  清歌不尽
    2020-12-21 14:33

    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.

提交回复
热议问题