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

public static String getTotalInternalMemorySize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, totalBlocks * blockSize);
}

From source file:Main.java

public static FileFilter infoFileFilter() {
    return new FileFilter() {

        @Override//from  w w w  .ja v  a2 s.c  o  m
        public boolean accept(File pathname) {
            if (pathname.getPath().endsWith(".info"))
                return true;
            return false;
        }
    };
}

From source file:Main.java

public static String getDataDirectory(Context context) {
    File sdRoot = Environment.getExternalStorageDirectory();
    String path = sdRoot.getPath();
    String packageName = context.getPackageName();
    path = path + File.separator + "Android" + File.separator + "data" + File.separator + packageName
            + File.separator + "files" + File.separator;
    return path;//www.  jav  a 2s . c om
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the
 *         given File//from  www  .  jav  a 2s  .  co m
 */
@SuppressLint("NewApi")
public static long getAvailableBytes(File root) {
    StatFs stat = new StatFs(root.getPath());
    // put a bit of margin (in case creating the file grows the system by a
    // few blocks)
    if (android.os.Build.VERSION.SDK_INT < 18) {
        long availableBlocks = (long) stat.getAvailableBlocks() - 4;

        return stat.getBlockSize() * availableBlocks;
    } else {
        long availableBlocks = (long) stat.getAvailableBlocksLong() - 4;
        return stat.getBlockSizeLong() * availableBlocks;
    }
}

From source file:Main.java

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

    return availableBlocks * blockSize;
}

From source file:Main.java

/**
 * get the space is left over on phone self
 *//*from ww  w  . j  a  v  a2  s.c  o m*/
public static long getRealSizeOnPhone() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return blockSize * availableBlocks;
}

From source file:Main.java

public static String getSDCardPath() {
    if (isSDCardExist()) {
        File file = Environment.getExternalStorageDirectory();
        return file.getPath();
    } else {/*from  w  w w.ja v a  2s. com*/
        return null;
    }
}

From source file:Main.java

public static String getMemFreeSize(Context ctx) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(ctx, blockSize * availableBlocks);
}

From source file:Main.java

public static String getMemTotalSize(Context ctx) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(ctx, blockSize * totalBlocks);
}

From source file:Main.java

private static String getSavedPostsPath(Context context) {
    String dir = String.format("/Android/data/%s/files/", context.getPackageName());
    File sd = Environment.getExternalStorageDirectory();
    String filePath = sd.getPath() + dir + "savedPosts.txt";

    new File(sd.getPath() + dir).mkdirs();

    return filePath;
}