Get folder size

前端 未结 8 1195
生来不讨喜
生来不讨喜 2020-12-30 06:27

Do you know how can I get the folder size in Java?

The length() method in the File class only works for files, using that method I always get a size of 0.

8条回答
  •  抹茶落季
    2020-12-30 06:53

    import java.io.File;
    import org.apache.commons.io.FileUtils;
    
    public class FolderSize
    {
      public static void main(String[] args)
       {
        long size = FileUtils.sizeOfDirectory(new File("C:/Windows/folder"));
    
        System.out.println("Folder Size: " + size + " bytes");
       }
    }
    

提交回复
热议问题