How to traverse a directory structure in Java
In this example, the program will traverse the given directory and print out all the directories and files absolute path and name one by one.
Favourite tutorials for developers
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need to recompile.
In this example, the program will traverse the given directory and print out all the directories and files absolute path and name one by one.
If we use the NIO Files.delete to delete a non-empty directory in Java, it throws DirectoryNotEmptyException; for legacy IO File.delete to delete a non-empty directory, it returns a false. The…
In Java, we can use the NIO Files.createDirectory to create a directory or Files.createDirectories to create a directory including all nonexistent parent directories. For legacy IO java.io.File, the similar methods…
In Java, we can use the NIO createFile() to assign file permission during file creation. But, the createFile() fails to assign the group writes file permission to a file on…
In Java, we can use System.getProperty("java.io.tmpdir") to get the default temporary file location. For Windows, the default temporary folder is %USER%\AppData\Local\Temp. For Linux, the default temporary folder is /tmp .…
In Java, we can use the NIO Files.delete() or Files.deleteIfExists() to delete a temporary file, it works the same like delete a regular text file. We also can uses the…
The temporary file is just a regular file created on a predefined directory. In Java, we can use the NIO Files.write() to write data to a temporary file. In Java,…
In Java, we can use the Java NIO Files.createTempFile() methods to create a temporary file in the default temporary-file directory. The default temporary file folder is vary on operating system:…
In last section, you learn about how to compress a serialized object into a file, now you learn how to decompress it from a Gzip file. The idea is very…
In last section, you learn about how to write or serialized an object into a file. In this example , you can do more than just serialized it , you…