Example usage for java.io File getAbsolutePath

List of usage examples for java.io File getAbsolutePath

Introduction

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

Prototype

public String getAbsolutePath() 

Source Link

Document

Returns the absolute pathname string of this abstract pathname.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static long getAvailable(final File dir) {
    final StatFs statFs = new StatFs(dir.getAbsolutePath());
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return ((long) statFs.getBlockCount()) * statFs.getBlockSize();
    }/*from ww w.j a  va2s. c om*/
    return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
}

From source file:Main.java

public static synchronized Bitmap getTempBitmap(Context context, String filename) {
    File path = new File(getTempDirectory(context), filename);
    return decodeSampledBitmapFromFile(path.getAbsolutePath());
}

From source file:Main.java

public static String getSdCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

        if (true) {
            Context appContext = context.getApplicationContext();

            File amap = appContext.getExternalFilesDir("offlineMap");
            return amap.getAbsolutePath() + "/";
        } else {//from   w ww  .ja  v a  2 s  .  c o  m

            File fExternalStorageDirectory = Environment.getExternalStorageDirectory();
            File autonaviDir = new File(fExternalStorageDirectory, "amapsdk");
            boolean result = false;
            if (!autonaviDir.exists()) {
                result = autonaviDir.mkdir();
            }
            File minimapDir = new File(autonaviDir, "offlineMap");
            if (!minimapDir.exists()) {
                result = minimapDir.mkdir();
            }
            return minimapDir.toString() + "/";
        }

    } else {
        return "";
    }
}

From source file:Main.java

public static String getExternalFullPath(Context context, String fileName) {
    File dir = context.getExternalFilesDir(null);
    if (dir == null) {
        return null;
    }/* w  w w  .  j a v  a2 s.co  m*/
    return dir.getAbsolutePath() + "/" + fileName;
}

From source file:com.adguard.compiler.PackageUtils.java

public static File createZip(String makeZipSh, File file) throws Exception {
    execute(makeZipSh, file.getAbsolutePath());
    File zipFile = new File(file, file.getName() + ".zip");
    File destZipFile = new File(file.getParentFile(), zipFile.getName());
    FileUtils.deleteQuietly(destZipFile);
    FileUtils.moveFile(zipFile, destZipFile);
    return destZipFile;
}

From source file:Main.java

public static String getInstanceFolder(String appName, String tableId, String instanceId) {
    String path;//  w  w w  .  j  av a  2 s .  c  o m
    if (instanceId == null || instanceId.length() == 0) {
        throw new IllegalArgumentException("getInstanceFolder: instanceId is null or the empty string!");
    } else {
        String instanceFolder = instanceId.replaceAll("(\\p{P}|\\p{Z})", "_");

        path = getTablesFolder(appName, tableId) + File.separator + INSTANCES_FOLDER_NAME + File.separator
                + instanceFolder;
    }

    File f = new File(path);
    f.mkdirs();
    return f.getAbsolutePath();
}

From source file:Main.java

public static boolean isCityExist(Context context, String city) {
    File file = new File(context.getFilesDir(), DATABASE_NAME);
    SQLiteDatabase db = context.openOrCreateDatabase(file.getAbsolutePath(), Context.MODE_PRIVATE, null);
    Cursor cursor = db.rawQuery("select count(1) from " + TABLE_NAME + " where DQXX02=?",
            new String[] { city });
    cursor.moveToNext();/*  w  w w  . j  ava2 s. c  om*/
    return cursor.getInt(0) > 0;
}

From source file:com.homeproject.tafulop.fxtest.FileHandling.java

/**
 * Returns a File which points to the newly created resized file. Automatically created the necessary folders.
 * @param toResize The File that should be resized.
 * @return The File points to the new, resized file.
 *///from ww  w. j  ava 2s .  com
public static File getResizedFile(File toResize) {

    File resizedFolder = checkResizedFolder(toResize.getParent());
    File resizedFile = new File(resizedFolder.getAbsolutePath() + DIR_SEPARATOR + toResize.getName());
    return resizedFile;
}

From source file:Main.java

public static boolean save(String fileName, Bitmap bitmap) {
    if (fileName == null || bitmap == null) {
        return false;
    }//ww  w  .  j  a  v  a2 s.  co m
    boolean savedSuccessfully = false;
    OutputStream os = null;
    File imageFile = new File(fileName);
    File tmpFile = new File(imageFile.getAbsolutePath() + ".tmp");
    try {
        if (!imageFile.getParentFile().exists()) {
            imageFile.getParentFile().mkdirs();
        }
        os = new BufferedOutputStream(new FileOutputStream(tmpFile));
        savedSuccessfully = bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (savedSuccessfully && tmpFile != null && !tmpFile.renameTo(imageFile)) {
            savedSuccessfully = false;
        }
        if (!savedSuccessfully) {
            tmpFile.delete();
        }
    }
    return savedSuccessfully;
}

From source file:Main.java

public static String getModelPath(String modelName, Context mContext) {
    String path = null;/* www.  j av a 2 s.  c  om*/
    File dataDir = mContext.getApplicationContext().getExternalFilesDir(null);
    if (dataDir != null) {
        path = dataDir.getAbsolutePath() + File.separator + modelName;
    }
    return path;
}