且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java:如何在java中将File对象转换为String对象?

更新时间:2022-11-18 20:07:02

我使用 apache common IO 将文本文件读入单个字符串

I use apache common IO to read a text file into a single string

String str = FileUtils.readFileToString(file);

简单和干净。你甚至可以毫无困难地设置文本文件的编码。

simple and "clean". you can even set encoding of the text file with no hassle.

String str = FileUtils.readFileToString(file, "UTF-8");