get Free Space using File class by path string - Android File Input Output

Android examples for File Input Output:File System

Description

get Free Space using File class by path string

Demo Code


//package com.java2s;

import java.io.File;

public class Main {
    public static long getFreeSpace(String path) {
        File file = new File(path);
        if (!(file.isDirectory() && file.exists())) {
            file.mkdirs();/*  w ww .  j  av  a  2 s  .c  om*/
            if (file.isDirectory()) {
                return file.getFreeSpace();
            } else {
                return 0L;
            }
        } else {
            return file.getFreeSpace();
        }
    }
}

Related Tutorials