Java RandomAccessFile与DataInputStream进行字节操作 [英] Java RandomAccessFile vs. DataInputStream for byte operations
问题描述
我需要从文件中读取字节。
使用 RandomAccessFile $ c>之间是否有区别(例如效率,内存,运行时,复杂性和代码的不雅感) $ c $>使用
DataInputStream
?
我使用的唯一方法是readByte()。
对于另一个方向,同样的情况是, RandomAccessFile
和 DataOutputStream
如果所有需要的是writeByte()?
(事实上, RandomAccessFile
是双向的不计数,读写没有连接,不能分享)
是否还有其他更适合这种阅读和写作的对象?
FileInputStream
的 BufferedInputStream
周围的 DataInputStream
将会是比 RandomAccessFile
更有效率。 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
and using DataInputStream
?
The only method I use is readByte().
Similarly for the other direction, is there a difference between RandomAccessFile
and DataOutputStream
if all that is needed is writeByte()?
(The fact that RandomAccessFile
is bidirectional doesn't count, the reading and writing are not connected and cannot share it).
Is there any other object that would better suit that kind of reading and writing?
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
.
这篇关于Java RandomAccessFile与DataInputStream进行字节操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!