Directory Size in java code example

How to get Directory Size in java code example?

public static long getDirectorySize(String directoryPath)
    {
        dirSize = 0L;
        dirSize = calDirectorySize(directoryPath);
        return dirSize;
    }

 private static long calDirectorySize(String directoryPath)
    {
        File fd = new File(directoryPath);
        if(!fd.isFile())
        {
            String list[] = fd.list();
            for(int i = 0; i < list.length; i++)
            {
                String tempDirPath = directoryPath + fileDelimiter + list[i];
                File ftd = new File(tempDirPath);
                if(ftd.isFile())
                    dirSize += ftd.length();
                if(ftd.isDirectory())
                    calDirectorySize(tempDirPath);
            }

        }
        return dirSize;
    }

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Shallow Copy Deep Copy Java example

Database Connection using NODE JS example