File Transfer using SFTP in Java (JSch)
This article shows how to do file transfer from a remote server to the local system and vice versa, using SSH File Transfer Protocol (SFTP) in Java. This Java example…
How to move file to another directory in Java
This article shows, in Java, how to move a file to another directory in the same file drive or remote server: (1) Files.move – Move file in local system, (2)…
How to rename or move a file in Java
In Java, we can use the NIO Files.move(source, target) to rename or move a file. The Apache FileUtils.moveFile uses a "copy and delete" mechanism to rename or move a file.…
Java – How to list all files in a directory?
Two Java examples to show you how to list files in a directory: For Java 8, use Files.walk. Before Java 8, create a recursive loop to list all files.
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…
How to copy directory in Java
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…
How to get file extension in Java
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…
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…