Java RandomAccessFile与DataInputStream进行字节操作 [英] Java RandomAccessFile vs. DataInputStream for byte operations

查看:133
本文介绍了Java RandomAccessFile与DataInputStream进行字节操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从文件中读取字节。

使用 RandomAccessFile 之间是否有区别(例如效率,内存,运行时,复杂性和代码的不雅感) $ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆