Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 整个文本文件到 Java 中的字符串
如何将文本文件读到最后?
实际上我需要将整个文件输出到屏幕上,因此我认为我需要将文件中的整个数据作为String.
String
使用FileUtils的readFileToString()方法。
readFileToString()
String content = FileUtils.readFileToString(new File("file.txt"), "utf-8");