在内存中加载文本文件的最快/最干净的方法

Sim*_*eon 9 java performance coding-style text-files

我之前已经问过类似的问题,但我找不到能回答我确切问题的问题.

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

我不是在寻找:

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

  // logic
}
Run Code Online (Sandbox Code Playgroud)

而且我知道我可以写自己的助手类来做到这一点.

我正在寻找更多的东西:

final String wholeFileAsStr = Something.load(file);
Run Code Online (Sandbox Code Playgroud)

哪里Something.load()是超级优化,而阅读呢,正在文件的大小考虑,例如适当缓冲文件.

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

提前致谢.

nos*_*nos 5

也许IOUtils.toString,从共享IOUtils