How to get the filepath of a file in Java
In Java, for NIO Path, we can use path.toAbsolutePath() to get the file path; For legacy IO File, we can use file.getAbsolutePath() to get the file path.For symbolic links or…
Favourite tutorials for developers
Core Java is the fundamental form of Java. We use it in all Java platforms and technologies. Without going through core Java, it is impossible to advance to advanced Java. Unlike core Java, advanced Java is a specialization of the core Java in some particular domain, such as database handling, networking, and the web.
In Java, for NIO Path, we can use path.toAbsolutePath() to get the file path; For legacy IO File, we can use file.getAbsolutePath() to get the file path.For symbolic links or…
In Java, we can use the Java 1.7 FileVisitor or Apache Commons IO FileUtils.copyDirectory to copy a directory, which includes its sub-directories and files. This article shows a few of…
This article shows how to get the file extension of a file in Java. This example shows how to use String#lastIndexOf to get the file extension of a file, and…
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…
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…
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…
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…