Java create and write to a file
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…
Favourite tutorials for developers
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…
In Java, we can use BufferedWriter to write content into a file, safety with try-resources in Java 7+. If possible, uses Files.write instead, one line, simple and nice. For Append…
In Java, we use FileInputStream to read bytes from a file, such as an image file or binary file. The FileInputStream.read() reads a byte at a time, and it will…
In Java, FileOutputStream is a bytes stream class that’s used to handle raw binary data. To write the data to file, you have to convert the data into bytes and…
In Java, we can use System.getProperty("user.dir") to get the current working directory, the directory from where your program was launched. The article shows different ways like File, Paths, FileSystems, or…
In this tutorial, we will show you three Java examples to construct a file path : (1) File.separator or System.getProperty(“file.separator”) (Recommended), (2) File file = new File(workingDir, filename); (Recommended), (3)…
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…
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…
The BufferedReader reads characters; while the InputStream is a stream of bytes. The BufferedReader can’t read the InputStream directly; So, we need to use an adapter like InputStreamReader to convert…
This article shows four ways to copy a file in Java: (1) Files.copy (NIO), (2) Apache Commons IO, (3) Guava, (4) Plain Java. In Java 7+, the NIO Files.copy is…