I want to read each line from a text file and store them in an ArrayList (each line being one entry in the ArrayList).

我想从文本文件中读取每一行并将它们存储在ArrayList中(每一行都是ArrayList中的一个条目)。

So far I understand that a BufferedInputStream writes to the buffer and only does another read once the buffer is empty which minimises or at least reduces the amount of operating system operations.

到目前为止,我理解buffer爱丁堡putstream向缓冲区写入,并且只有在缓冲区为空时才进行另一次读取,这将最小化或至少减少操作系统操作的数量。

Am I correct - do I make sense?

我是对的吗?

If the above is the case in what situations would anyone want to use DataInputStream. And finally which of the two should I be using and why - or does it not matter.

如果上面的情况是这样的,那么在什么情况下,任何人都希望使用DataInputStream。最后,我应该使用这两种方法中的哪一种,为什么-或者它不重要。

6 个解决方案

#1


16

Use a normal InputStream (e.g. FileInputStream) wrapped in an InputStreamReader and then wrapped in a BufferedReader - then call readLine on the BufferedReader.

使用通常的InputStream(例如FileInputStream)包装在InputStreamReader中,然后包装在BufferedReader中——然后在BufferedReader上调用readLine。

DataInputStream is good for reading primitives, length-prefixed strings etc.

DataInputStream适用于读取原语、长前缀字符串等。

更多相关文章

  1. Java nio 学习笔记(一) Buffer(缓冲区)与Channel(通道)的相关知识
  2. Java IO流系列(四)—— 从字节流及其缓冲区到转换流
  3. Java的Grizzly为缓冲区占用了大量内存?

随机推荐

  1. JavaScript 高阶函数快速入门 [每日前端
  2. 分享十张表的数据!大家一起玩!
  3. 2019年 Vue.js 报告中的亮点 [每日前端夜
  4. 用python重新定义【2019十大网络流行语】
  5. 用 Node.js 写一个多人游戏服务器引擎 [
  6. 三十天写三十个网站后,我学到的东西[每日
  7. 14个最好的 JavaScript 数据可视化库[每
  8. deno如何偿还Node.js的十大技术债 [每日
  9. 11个最好的JavaScript动态效果库[每日前
  10. React教程:组件,Hooks和性能 [每日前端夜话