Maven compiles and hits the following fatal error messages: Fatal error compiling: error: invalid target release: 1.11 . The article will show you how to fix this error
This article shows how to use the following Java APIs to append text to the end of a file. (1) Files.write – Append a single line to a file, Java 7. (2) Files.write – Append multiple lines to a file, Java 7, Java 8. (3) Files.writeString – Java 11. (4) FileWriter, (5) FileOutputStreamFileUtils – Apache Commons IO. In Java, for NIO APIs like Files.write, we can use StandardOpenOption.APPEND to enable the append mode. For classic IO APIs like FileWriter or FileOutputStream, we can pass a true to the constructor’s second argument to enable the append mode.
In Java, we can use Files.write to create and write to a file. The Files.write also accepts an Iterable interface; it means this API can write a List to a file. Before Java 7, for writing bytes (image) to a file, we use FileOutputStream; for writing characters (text) to a file, we use FileWriter, and usually wrapped by a BufferedWriter to gain performance. In Java 7, there is a new NIO class named java.nio.file.Files, and we can use Files.write() to write both bytes and characters. In Java 8, we can use Files.newBufferedWriter(path) to create a BufferedWriter. In Java 11, there is a new Files.writeString API to write string directly to a file.
A series of Java 8 up to date tips and examples, hope you like it. Java 11 reached General Availability on 25 September 2018, this is a Long Term Support (LTS) version. Java 12 reached General Availability on 19 March 2019. Java 13 reached General Availability on 17 September 2019. Java 14 reached General Availability on 17 March 2020. Java 15 reached General Availability on 15 September 2020. Java 16 reached General Availability on 16 March 2021. Java 17 is a long-term support (LTS) release, reached General Availability on 14 September 2021.
In Java, the InputStreamReader accepts a charset to decode the byte streams into character streams. We can pass a StandardCharsets.UTF_8 into the InputStreamReader constructor to read data from a UTF-8 file. In Java 7+, many file read APIs start to accept charset as an argument, making reading a UTF-8 very easy.
In Java, the OutputStreamWriter accepts a charset to encode the character streams into byte streams. We can pass a StandardCharsets.UTF_8 into the OutputStreamWriter constructor to write data to a UTF-8 file. In Java 7+, many File I/O and NIO writers start to accept charset as an argument, making write data to a UTF-8 file very easy.
This Java 11 JEP 332 adds support for TLS 1.3 protocol. This article will demo for An SSLSocket client with TLS1.3 protocol and TLS_AES_128_GCM_SHA256 stream cipher, to send a request to https://google.com and print the response.
In this article, we will show you a few examples to make HTTP GET/POST requests via the following APIs: Apache HttpClient 4.5.13, OkHttp 4.2.2, Java 11 HttpClient, Java 1.1 HttpURLConnection (Not recommend)
This article focus on a few of the commonly used methods to read a file in Java. 1 – Files.lines, return a Stream (Java 8), 2 – Files.readString, returns a String (Java 11), max file size 2G. 3 – Files.readAllBytes, returns a byte (Java 7), max file size 2G. 4 – Files.readAllLines, returns a List