本文介绍了最快/最干净的方式在内存中加载文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道类似的问题以前被问过,但是我找不到能回答我确切问题的问题。

I know similar questions have been asked before, but I couldn't find one that answers my exact question.

我需要一种方法来读取文件 String 使用最少的代码,尽可能简单和最优。

I need a way to read a file as a String with the least code and as simple and as optimal as possible.

我不在找: / p>

I'm not looking for:

final BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {

  // logic
}

我知道我可以写自己的帮助类来做这个。

And I know I can write my own helper class that does this.

我在找东西更多的沿线:

I'm looking for something more along the lines of:

final String wholeFileAsStr = Something.load(file);

其中 Something.load()

任何人都可以从Guava或Apache推荐一些我可能不知道的东西?

Can anyone recommend something from Guava or Apache maybe that I'm not aware of ?

提前感谢。

推荐答案

http://commons.apache.org/io/api-1.2/org/apache/commons/io/IOUtils.html#toString%28java.io.InputStream%29rel =nofollow> IOUtils.toString ,来自Commons IOUtils

Perhaps IOUtils.toString , from Commons IOUtils

这篇关于最快/最干净的方式在内存中加载文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:37