Home >Java >javaTutorial >Java Example - Get Directory Size

Java Example - Get Directory Size

黄舟
黄舟Original
2017-02-13 10:06:151452browse

The following example demonstrates using FileUtils.sizeofDirectory(File Name) of the File class to obtain the size of the directory:

/*
 author by w3cschool.cc
 Main.java
 */import java.io.File;import org.apache.commons.io.FileUtils;public class Main {
   public static void main(String[] args) {
      long size = FileUtils.sizeOfDirectory      (new File("C:/test"));
      System.out.println("Size: " + size + " bytes");
   }

The output result of running the above code is:

Size: 2048 bytes

The above is the Java example - Get the content of the directory size. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn