Utils将资源文本文件读取为String(Java) [英] Utils to read resource text file to String (Java)

查看:114
本文介绍了Utils将资源文本文件读取为String(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何实用程序可以帮助将资源中的文本文件读入String。我想这是一个很受欢迎的要求,但我在谷歌搜索后找不到任何实用程序。

Is there any utility that helps to read a text file in the resource into a String. I suppose this is a popular requirement, but I couldn't find any utility after Googling.

推荐答案

是的,Guava 资源 类。例如:

Yes, Guava provides this in the Resources class. For example:

URL url = Resources.getResource("foo.txt");
String text = Resources.toString(url, Charsets.UTF_8);

这篇关于Utils将资源文本文件读取为String(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆