Example usage for android.content Context getFilesDir

List of usage examples for android.content Context getFilesDir

Introduction

In this page you can find the example usage for android.content Context getFilesDir.

Prototype

public abstract File getFilesDir();

Source Link

Document

Returns the absolute path to the directory on the filesystem where files created with #openFileOutput are stored.

Usage

From source file:Main.java

public static boolean fileExists(Context context, String fileName) {
    return new File(context.getFilesDir() + File.separator + fileName).exists();
}

From source file:Main.java

private static synchronized File getTempDirectory(Context context) {
    File tempDir = new File(context.getFilesDir(), "temps/");
    if (!tempDir.exists()) {
        tempDir.mkdirs();/*w  w  w  . j ava2  s .c om*/
    }
    return tempDir;
}

From source file:Main.java

public static String ConfigureGetIniPath(Context context) {
    if (context != null) {
        File file = context.getFilesDir();
        return file.getAbsolutePath();
    } else {//from   w  w w .j  ava2s.  c o m
        return "/data/data/com.youplayer.player/files";
    }
}

From source file:Main.java

/**
 * Get a writeable cache directory for saving cache files
 *
 * @param context//  w  w w .ja  v  a  2 s .com
 * @return file directory or null
 */
public static File getApplicationCacheDirectory(Context context) {
    File directory = context.getFilesDir();

    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File externalDirectory = context.getExternalFilesDir(null);
        if (externalDirectory != null) {
            directory = externalDirectory;
        }
    }

    File cacheDirectory = new File(directory, CACHE_DIRECTORY);
    if (!cacheDirectory.exists()) {
        cacheDirectory.mkdir();
    }

    return cacheDirectory;
}

From source file:Main.java

public static Bitmap getBitmap(Context context, String picName) {
    Bitmap bitmap = BitmapFactory.decodeFile(context.getFilesDir().toString() + "/" + picName);
    return bitmap;
}

From source file:Main.java

public static void cleanDatabases(Context context) {
    deleteFilesByDirectory(new File(
            context.getFilesDir().getPath() + context.getPackageName() + File.separator + "databases"));
}

From source file:Main.java

public static void cleanSharedPreference(Context context) {
    deleteFilesByDirectory(new File(
            context.getFilesDir().getPath() + context.getPackageName() + File.separator + "shared_prefs"));
}

From source file:Main.java

private static File getKeysDirectory(Context context, String name) {
    File directory = new File(context.getFilesDir(), name);

    if (!directory.exists())
        directory.mkdirs();/*from  w  w w.  j  ava  2  s  . c om*/

    return directory;
}

From source file:Main.java

/**
 * Removes entities file./* w ww .j a v a2  s.co  m*/
 * @param context
 * @param fileName
 * @throws Exception 
 */
public static void removeAllEntities(Context context, String fileName) throws Exception {
    File file = new File(context.getFilesDir(), fileName);
    boolean deleted = file.delete();
    if (!deleted) {
        throw new Exception("Failed to remove file=" + fileName);
    }
}

From source file:Main.java

static File getFilesDirectory(Context context) {
    // creates files directory under data/data/package name
    return context.getFilesDir();
}