如果想对一个文本文件一行行的读,然后在对每行数据处理 用JAVA的IO流里的哪个类效率最高啊

大地之子 2014-04-18 04:10:34
如果想对一个文本文件一行行的读,然后在对每行数据处理 用JAVA的IO流里的哪个类效率最高啊
...全文
305 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
大地之子 2014-04-18
  • 打赏
  • 举报
回复
引用 6 楼 wlwlwlwl015 的回复:
[quote=引用 5 楼 u014039623 的回复:] [quote=引用 3 楼 wlwlwlwl015 的回复:] [quote=引用 2 楼 u014039623 的回复:] [quote=引用 1 楼 wlwlwlwl015 的回复:] 读一行的话就用BufferedReader,它有个readLine()方法,就是返回一行的数据,参考一下官方文档: public String readLine() throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs See Also: Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
要包装吗 我看网上人家读文件都是一层包着一层的流 不知道一行一行读文件用哪个IO的文件流最快啊 好多网上都是一层包一层啊 你是怎么写的呢[/quote] Java的IO流的设计就是装饰模式,你看到的一层一层就是这样。比如:

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("csdn.txt")));
而且BufferedReader本身设计的就是通过缓冲方式读取文本,减少了很多io操作,效率还是相当高的。[/quote]好的 3QS 是不是直接就BufferedReader br = new BufferedReader("csdn.txt"); 然后就可以一行一行的读了啊[/quote] 不行啊,bufferedreader的构造函数必须要传一个read对象: Constructor and Description BufferedReader(Reader in) Creates a buffering character-input stream that uses a default-sized input buffer. 你直接读本地文件用我上面写的就可以。[/quote]灰常感谢啊
小灯光环 2014-04-18
  • 打赏
  • 举报
回复
引用 5 楼 u014039623 的回复:
[quote=引用 3 楼 wlwlwlwl015 的回复:] [quote=引用 2 楼 u014039623 的回复:] [quote=引用 1 楼 wlwlwlwl015 的回复:] 读一行的话就用BufferedReader,它有个readLine()方法,就是返回一行的数据,参考一下官方文档: public String readLine() throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs See Also: Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
要包装吗 我看网上人家读文件都是一层包着一层的流 不知道一行一行读文件用哪个IO的文件流最快啊 好多网上都是一层包一层啊 你是怎么写的呢[/quote] Java的IO流的设计就是装饰模式,你看到的一层一层就是这样。比如:

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("csdn.txt")));
而且BufferedReader本身设计的就是通过缓冲方式读取文本,减少了很多io操作,效率还是相当高的。[/quote]好的 3QS 是不是直接就BufferedReader br = new BufferedReader("csdn.txt"); 然后就可以一行一行的读了啊[/quote] 不行啊,bufferedreader的构造函数必须要传一个read对象: Constructor and Description BufferedReader(Reader in) Creates a buffering character-input stream that uses a default-sized input buffer. 你直接读本地文件用我上面写的就可以。
大地之子 2014-04-18
  • 打赏
  • 举报
回复
引用 3 楼 wlwlwlwl015 的回复:
[quote=引用 2 楼 u014039623 的回复:] [quote=引用 1 楼 wlwlwlwl015 的回复:] 读一行的话就用BufferedReader,它有个readLine()方法,就是返回一行的数据,参考一下官方文档: public String readLine() throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs See Also: Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
要包装吗 我看网上人家读文件都是一层包着一层的流 不知道一行一行读文件用哪个IO的文件流最快啊 好多网上都是一层包一层啊 你是怎么写的呢[/quote] Java的IO流的设计就是装饰模式,你看到的一层一层就是这样。比如:

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("csdn.txt")));
而且BufferedReader本身设计的就是通过缓冲方式读取文本,减少了很多io操作,效率还是相当高的。[/quote]好的 3QS 是不是直接就BufferedReader br = new BufferedReader("csdn.txt"); 然后就可以一行一行的读了啊
小灯光环 2014-04-18
  • 打赏
  • 举报
回复
引用 2 楼 u014039623 的回复:
[quote=引用 1 楼 wlwlwlwl015 的回复:] 读一行的话就用BufferedReader,它有个readLine()方法,就是返回一行的数据,参考一下官方文档: public String readLine() throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs See Also: Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
要包装吗 我看网上人家读文件都是一层包着一层的流 不知道一行一行读文件用哪个IO的文件流最快啊 好多网上都是一层包一层啊 你是怎么写的呢[/quote] Java的IO流的设计就是装饰模式,你看到的一层一层就是这样。比如:

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("csdn.txt")));
而且BufferedReader本身设计的就是通过缓冲方式读取文本,减少了很多io操作,效率还是相当高的。
大地之子 2014-04-18
  • 打赏
  • 举报
回复
引用 1 楼 wlwlwlwl015 的回复:
读一行的话就用BufferedReader,它有个readLine()方法,就是返回一行的数据,参考一下官方文档: public String readLine() throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs See Also: Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
要包装吗 我看网上人家读文件都是一层包着一层的流 不知道一行一行读文件用哪个IO的文件流最快啊 好多网上都是一层包一层啊 你是怎么写的呢
小灯光环 2014-04-18
  • 打赏
  • 举报
回复
读一行的话就用BufferedReader,它有个readLine()方法,就是返回一行的数据,参考一下官方文档: public String readLine() throws IOException Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs See Also: Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧