用Java读取纯文本文件

编程入门 行业动态 更新时间:2024-10-12 08:20:40
本文介绍了用Java读取纯文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 Java 中,似乎有不同的方式来读取和写入文件数据.

It seems there are different ways to read and write data of files in Java.

我想从文件中读取 ASCII 数据.有哪些可能的方式和区别?

I want to read ASCII data from a file. What are the possible ways and their differences?

推荐答案

ASCII 是一个文本文件,所以你可以使用 Readers 用于阅读.Java 还支持使用 InputStreams 从二进制文件中读取.如果正在读取的文件很大,那么您需要使用 BufferedReader 在 FileReader 以提高读取性能.

ASCII is a TEXT file so you would use Readers for reading. Java also supports reading from a binary file using InputStreams. If the files being read are huge then you would want to use a BufferedReader on top of a FileReader to improve read performance.

阅读这篇文章,了解如何使用读者

我还建议您下载并阅读这本精彩(但免费)的书,名为思考在 Java 中

I'd also recommend you download and read this wonderful (yet free) book called Thinking In Java

在 Java 7 中:

new String(Files.readAllBytes(...))

(文档)或

Files.readAllLines(...)

(文档)

在 Java 8 中:

Files.lines(..).forEach(...)

(文档)

更多推荐

用Java读取纯文本文件

本文发布于:2023-10-12 04:36:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!