import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String content = new String(Files.readAllBytes(Paths.get("duke.java"))); String content=new String(Files.readAllBytes(file.toPath()),Charset.forName("UTF-8"));//specify the charset }
Java8:读取文件到一个字符串
最新推荐文章于 2024-05-08 23:33:36 发布