Skip to content
Advertisement

Tag: filesystems

How to get the inmediate child directory of a file path in Java?

I want to navigate the file system and get the path to the child of a directory (if exists) without the root. For example: Input: Users/Documents/SVG Output: Documents/SVG My solution so far is to hardcode a string manipulation of the path: Is there a more elegant way to do this? Answer Path.relativize() can help You can convert this Path back

Hadoop 2.6.0 Browsing filesystem Java

I have installed a basic hadoop cluster on CentOS 6.6 and want to write a few basic programs (browse the filesystem, delete/add files, etc) but I’m struggling to get even the most basic app working. When running some basic code to list the contents of a directory to the console I get the following error: My pom.xml dependencies The code:

Get size of folder or file

How can I retrieve size of folder or file in Java? Answer This returns the length of the file in bytes or 0 if the file does not exist. There is no built-in way to get the size of a folder, you are going to have to walk the directory tree recursively (using the listFiles() method of a file object

Advertisement