This topic is about Java 11 – File APIs.
Java 11 introduced an easy way to read and write files by providing new overloaded methods without writing much boiler plate code.
Consider the following example −
ApiTester.java
import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; public class APITester { public static void main(String[] args) { try { Path tempFilePath = Files.writeString( Path.of(File.createTempFile("tempFile", ".tmp").toURI()), "Welcome to Adglob", Charset.defaultCharset(), StandardOpenOption.WRITE); String fileContent = Files.readString(tempFilePath); System.out.println(fileContent); } catch (IOException e) { e.printStackTrace(); } } }
Output
Welcome to Adglob
In this topic we learned about Java 11 – File APIs. To learn more, Click Here.
Pingback: Java 11 - Compile free Launch - Adglob Infosystem Pvt Ltd