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

public static Intent getInstallIntent(File apkFile) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(apkFile.getAbsolutePath())),
            "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

From source file:Main.java

public static String getRootByApi() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File file = Environment.getExternalStorageDirectory();
        if (file == null)
            return null;
        String path = file.getAbsolutePath();
        if (isValidRoot(path))
            return path;
    }/*from   ww  w.j  a va 2  s.com*/
    return null;
}

From source file:Main.java

public static int getCameraPhotoOrientation(Uri imageUri) {
    int rotate = 0;
    try {/*from   w  w w . ja  va2 s. c o  m*/
        File imageFile = new File(imageUri.getPath());
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = 270;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = 90;
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}

From source file:Main.java

private static int getPhotoRotationDegree(String imagePath) {
    int rotate = 0;
    try {/* ww w . j  a va 2 s.c o  m*/
        File imageFile = new File(imagePath);
        ExifInterface exifDataReader = new ExifInterface(imageFile.getAbsolutePath());
        int orientation = exifDataReader.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = 270;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = 90;
            break;
        }
    } catch (IOException e) {
        Log.e("CATROID", "Could not find file to initialize ExifInterface.", e);
    }
    return rotate;
}

From source file:Main.java

public static void printFilePath(String pathname) {
    File f = new File(pathname);
    System.out.println("File  Name: " + f.getName());
    System.out.println("File  exists: " + f.exists());
    System.out.println("Absolute Path: " + f.getAbsolutePath());

    try {//w w w  .  j  ava  2s. c  o m
        System.out.println("Canonical Path: " + f.getCanonicalPath());
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.jivesoftware.os.jive.utils.shell.utils.Untar.java

public static String getRelativePath(File _root, File _file) {
    String home = _root.getAbsolutePath();
    String path = _file.getAbsolutePath();
    if (!path.startsWith(home)) {
        return null;
    }/*w w  w. ja va  2  s .  c  o  m*/
    int l = home.length() + 1;
    if (path.length() > l) {
        return path.substring(l);
    } else {
        return path;
    }
}

From source file:cu.uci.uengine.utils.FileUtils.java

public static String writeStringToFile(String fileName, File parent, String data) throws IOException {

    File sourceFile = new File(parent, fileName);

    writeStringToFile(sourceFile, data);

    return sourceFile.getAbsolutePath();
}

From source file:Main.java

public static List<String> getAllSkinZipFiles(String path) {
    List<String> zipFiles = new ArrayList<String>();
    File file = new File(path);
    if (file.exists()) {
        File[] files = file.listFiles();
        if (files.length > 0) {
            for (File f : files) {
                if (f.getName().startsWith("skin") && f.getName().endsWith("zip")) {
                    zipFiles.add(f.getAbsolutePath());
                }// ww  w. j a v a  2  s.c  om
            }
        }
    }
    return zipFiles;
}

From source file:Main.java

public static String getAbsPath(File file) {
    String path = null;//from w  ww  . j a  v a  2s.com
    try {
        path = file.getCanonicalPath();
    } catch (IOException e) {
        path = file.getAbsolutePath();
        Log.i("[explorer():]", e.toString());
    }

    return path;
}

From source file:com.cloudant.sync.datastore.DatastoreTestUtils.java

public static SQLDatabase createDatabase(String database_dir, String database_file)
        throws IOException, SQLException {
    String path = database_dir + File.separator + database_file + DATABASE_FILE_EXT;
    File dbFile = new File(path);
    FileUtils.touch(dbFile);//from ww  w .j av  a 2  s . c om
    SQLDatabase database = SQLDatabaseFactory.openSqlDatabase(dbFile.getAbsolutePath());
    SQLDatabaseFactory.updateSchema(database, DatastoreConstants.getSchemaVersion3(), 3);
    SQLDatabaseFactory.updateSchema(database, DatastoreConstants.getSchemaVersion4(), 4);
    SQLDatabaseFactory.updateSchema(database, DatastoreConstants.getSchemaVersion5(), 5);
    return database;
}