Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

In this page you can find the example usage for java.io File getPath.

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:Main.java

@SuppressLint("NewApi")
public static long getFreeDiskSpace() {
    String status = Environment.getExternalStorageState();
    long freeSpace = 0;
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSizeLong();
        long availableBlock = stat.getAvailableBlocksLong();
        freeSpace = availableBlock * blockSize / 1024;
    } else {/*from w  w  w .  ja  v  a2  s . c  om*/
        return -1;
    }
    return freeSpace;
}

From source file:Main.java

public static long getTotalExternalMemorySize() {
    if (isExternalMemoryAvailable() == true) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = 0;
        long totalBlocks = 0;
        blockSize = stat.getBlockSize();
        totalBlocks = stat.getBlockCount();

        return totalBlocks * blockSize;
    } else {//from  w w w  . ja  va2  s  . co m
        return -1;
    }
}

From source file:Main.java

public static List<String> getFolderContent(String folderDir) {
    File file = new File(folderDir);
    List<String> filesPath = new ArrayList<>();
    if (!file.exists()) {

    } else {/*  w  w  w  .  j  a v  a2  s  .co m*/
        for (File f : file.listFiles()) {
            if (f.isFile()) {
                filesPath.add(f.getPath());
            }
        }
    }
    return filesPath;
}

From source file:Main.java

/**
 * Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android
 * devices is stored in RAM.//from  w  w  w.  j a  v a  2 s.c  o m
 *
 * @return Number of bytes available.
 */
public static long getAvailableInternalMemorySize() {
    final File path = Environment.getDataDirectory();
    final StatFs stat = new StatFs(path.getPath());
    final long blockSize;
    final long availableBlocks;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        blockSize = stat.getBlockSizeLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        //noinspection deprecation
        blockSize = stat.getBlockSize();
        //noinspection deprecation
        availableBlocks = stat.getAvailableBlocks();
    }
    return availableBlocks * blockSize;
}

From source file:Main.java

/**
 * Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android
 * devices is stored in RAM.//from w  w  w . java 2s.  c o m
 *
 * @return Total number of bytes.
 */
public static long getTotalInternalMemorySize() {
    final File path = Environment.getDataDirectory();
    final StatFs stat = new StatFs(path.getPath());
    final long blockSize;
    final long totalBlocks;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        blockSize = stat.getBlockSizeLong();
        totalBlocks = stat.getBlockCountLong();
    } else {
        //noinspection deprecation
        blockSize = stat.getBlockSize();
        //noinspection deprecation
        totalBlocks = stat.getBlockCount();
    }
    return totalBlocks * blockSize;
}

From source file:Main.java

public static long getAvailaleSDCardSize() {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();

    long asize = availableBlocks * blockSize;
    LOG("getAvailaleSDCardSize asize: " + asize);
    return asize;
}

From source file:Main.java

@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
    long allSize;
    long availableSize = 0;
    try {//  w  w w  .  ja  v  a 2 s.c  om
        File data = Environment.getDataDirectory();
        StatFs sf = new StatFs(data.getPath());
        availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
        allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
    } catch (Exception e) {
        allSize = 0;
    }

    if (allSize != 0 && availableSize > limitSize) {
        return true;
    }
    return false;
}

From source file:net.orpiske.ssps.sdm.main.PluginRepositoryHelper.java

public static void addToGroovyClasspath(File pluginDir) {
    GroovyClasspathHelper helper = GroovyClasspathHelper.getInstance();

    if (pluginDir.exists()) {

        File pluginRepositories[] = pluginDir.listFiles((FileFilter) DirectoryFileFilter.INSTANCE);

        for (File pluginRepository : pluginRepositories) {
            helper.addClasspath(pluginRepository.getPath());
        }/*ww w.  j  a  v a  2 s  . c o  m*/
    }
}

From source file:Main.java

public static String removeExtention(String filePath) {
    File f = new File(filePath);

    // if it's a directory, don't remove the extention
    if (f.isDirectory())
        return filePath;

    String name = f.getName();/*from w ww . ja v  a2 s .  c om*/

    // Now we know it's a file - don't need to do any special hidden
    // checking or contains() checking because of:
    final int lastPeriodPos = name.lastIndexOf('.');
    if (lastPeriodPos <= 0) {
        // No period after first character - return name as it was passed in
        return filePath;
    } else {
        // Remove the last period and everything after it
        File renamed = new File(f.getParent(), name.substring(0, lastPeriodPos));
        return renamed.getPath();
    }
}

From source file:Main.java

public static long getFreeDiskSpace() {
    String status = Environment.getExternalStorageState();
    long freeSpace = 0;
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        try {/*from w  w w . j  ava 2s  .  co m*/
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long availableBlocks = stat.getAvailableBlocks();
            freeSpace = availableBlocks * blockSize / 1024;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        return -1;
    }
    return (freeSpace);
}