Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Environment;

import java.io.*;

public class Main {
    public static final String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();

    public static int getFolderSize(String relativePath) {
        int fileLength = 0;
        //      File dir = new File(path);
        File dir = creatSDDir(relativePath);
        if (dir.isDirectory()) {
            File[] files = dir.listFiles();
            for (File file : files) {
                fileLength += file.length();
            }
        } else {
            return -1;
        }
        return fileLength / 1024;
    }

    public static File creatSDDir(String dirRelativePath) {
        File dir = new File(SD_CARD_PATH + dirRelativePath);
        dir.mkdirs();
        return dir;
    }
}