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);
유효하지 않은(매핑이 불가능한) 문자를 처리할 때 readString()의 동작은 new String(bytes, charset)의 동작과는 다르다는 점에 유의하세요. readString() 메서드는 이러한 경우 예외를 던지며, new String(bytes, charset)는 유효하지 않은 문자를 대체 문자로 조용히 바꿉니다.
조용히 바꾸는 것이 바람직하다면 검사 경고를 억제하는 것이 좋습니다.
2018.3의 새로운 기능