Java, Java8, Java21, Java17, Migration.
new PrintWriter(new File("testWrite.txt"))) { // ... } Java 9 and After: final Scanner scanner = new Scanner(new File("testRead.txt")); final PrintWriter writer = new PrintWriter(new File("testWrite.txt")) try (scanner;writer) { // ... } This enhancement simplifies the code by allowing resources to