How to get file size in Java
In Java, we can use Files.size(path) to get the size of a file in bytes. This example uses NIO Files.size(path) to print the size of an image file (140 kb).…
Favourite tutorials for developers
In Java, we can use Files.size(path) to get the size of a file in bytes. This example uses NIO Files.size(path) to print the size of an image file (140 kb).…
A Java program to demonstrate the use of java.io.File setReadOnly() method to make a file read only. Since JDK 1.6, a new setWritable() method is provided to make a file…
In Java (@since 1.7), we can use the NIO Files.readAttributes to get all the file metadata, including the file creation date. We also can use the same code to get…
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…
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)…
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.…
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.
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…