Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

public class Main {
    public static long getFolderSize(File file) throws Exception {
        long size = 0;
        File[] fileList = file.listFiles();
        for (File f : fileList) {
            if (f.isDirectory()) {
                size += getFolderSize(f);
            } else {
                size += f.length();
            }
        }
        return size;
    }

    public static boolean isDirectory(String dir, String fileName) {
        return (new File(joinPath(dir, fileName)).isDirectory());
    }

    public static String joinPath(String... args) {
        StringBuilder stringBuilder = new StringBuilder();
        for (String arg : args) {
            stringBuilder.append(File.separator).append(arg.replaceAll("^/+", ""));
        }
        return stringBuilder.toString();
    }
}