Get file/directory size using Java 7 new IO

clamp picture clamp · Aug 31, 2011 · Viewed 25.8k times · Source

How can I get the size of a file or directory using the new NIO in java 7?

Answer

Joachim Sauer picture Joachim Sauer · Aug 31, 2011

Use Files.size(Path) to get the size of a file.

For the size of a directory (meaning the size of all files contained in it), you still need to recurse manually, as far as I know.