java.nio.file.Files
以字节形式读取或写入 String
的代码段。
这些代码段可以替换为对 Java 11 中引入的 Files.readString()
和 Files.writeString()
方法的调用。
示例:
String s = "example";
Files.write(Paths.get("out.txt"), s.getBytes(StandardCharsets.UTF_8), StandardOpenOption.WRITE);
s = new String(Files.readAllBytes(Paths.get("in.txt")), StandardCharsets.ISO_8859_1);
在应用快速修复后:
String s = "example";
Files.writeString(Paths.get("out.txt"), s, StandardOpenOption.WRITE);
s = Files.readString(Paths.get("in.txt"), StandardCharsets.ISO_8859_1);
2018.3 的新功能