How to find files with the file extension in Java
This article shows how to Java 8 Files.walk to walk a file tree and stream operation filter to find files that match a specific file extension from a folder and…
How to delete a file in Java
In Java, we can use the NIO Files.delete(Path) and Files.deleteIfExists(Path) to delete a file. The Files.delete(Path) deletes a file, returns nothing, or throws an exception if it fails. If the…
How to append text to a file in Java
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…
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…
How to write to file in Java – BufferedWriter
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…
How to read file in Java – FileInputStream
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…
How to write to file in Java – FileOutputStream
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…
How to read file in Java – BufferedInputStream
Here is another example to show how to read a file in Java with BufferedInputStream and DataInputStream classes. The readLine() from the type DataInputStream is deprecated. Sun officially announced this…
How to set the file permission in Java
In Java, file permissions are very OS specific: *nix , NTFS (windows) and FAT/FAT32, all have different kind of file permissions. Java comes with some generic file permission to deal…
Java : getResourceAsStream in static method
In non static method, we use getClass() of the object or instance. In static method, the getClass() method will be failed, and prompts Cannot make a static reference to the…