How to write a UTF-8 file in Java
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…
Favourite tutorials for developers
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…
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…
In Java, we can use Files.readAttributes() to get the file metadata or attribute, and then lastModifiedTime() to display the last modified date of a file. For legacy IO, we can…
In Java, we can use DateTimeFormatter to convert the FileTime to other custom date formats.
In Java, we can use the NIO Files.setLastModifiedTime(path, FileTime) to update the last modified date or time of a file. For legacy IO java.io.File, we can use File.setLastModified() to update…
The Files.find API is available since Java 8. It searches or finds files from a file tree quickly. Examples: Find files by filename, Find files by file size, Find files…
In Java, we can use getResourceAsStream or getResource to read a file or multiple files from a resources folder or root of the classpath. The getResourceAsStream method returns an InputStream.…
Below are some Java examples of converting InputStream to a File. Plain Java – FileOutputStream, Apache Commons IO – FileUtils.copyInputStreamToFile, Java 7 – Files.copy, Java 9 – InputStream.transferTo