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 String getContentType(File f) {
    int dotIndex = f.getAbsolutePath().lastIndexOf(".");
    if (dotIndex < 0) {
        return "application/octet-stream";
    }/*from  www .  j  av  a2 s . c om*/

    String suffix = f.getAbsolutePath().substring(dotIndex).toLowerCase();
    if ("jpg".equals(suffix) || "jpeg".equals(suffix))
        return "image/jpeg";
    else if ("png".equals(suffix) || "gif".equals(suffix))
        return "image/" + suffix;
    else if ("mp3".equals(suffix) || "mpeg".equals(suffix))
        return "audio/mpeg";
    else if ("mp4".equals(suffix) || "ogg".equals(suffix))
        return "audio/" + suffix;

    return "application/octet-stream";
}

From source file:Main.java

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

From source file:net.orfjackal.sbt.plugin.IO.java

public static String canonicalPathTo(File file) {
    return PathUtil.getCanonicalPath(file.getAbsolutePath());
}

From source file:Main.java

/**
 * Gets the free disk space at the specified location.
 *
 * @param dir//from ww  w  .  ja v a  2s  . c  o m
 *         the directory linking to the filesystem to query
 * @return the free disk space at {@code dir} in bytes
 */
private static long getFreeDiskSpace(File dir) {
    StatFs statFs = new StatFs(dir.getAbsolutePath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
    } else {
        //noinspection deprecation
        return statFs.getBlockCount() * statFs.getBlockSize();
    }
}

From source file:Main.java

public static File getSignatureFileFromFile(File originalFile) {
    return new File(originalFile.getAbsolutePath() + ".sig");
}

From source file:MakeDirectories.java

private static void fileData(File f) {
    System.out.println("Absolute path: " + f.getAbsolutePath() + "\n Can read: " + f.canRead()
            + "\n Can write: " + f.canWrite() + "\n getName: " + f.getName() + "\n getParent: " + f.getParent()
            + "\n getPath: " + f.getPath() + "\n length: " + f.length() + "\n lastModified: "
            + f.lastModified());/*from   w  w  w. j  av  a2  s.  c o  m*/
    if (f.isFile())
        System.out.println("It's a file");
    else if (f.isDirectory())
        System.out.println("It's a directory");
}

From source file:Main.java

public static String getDirectoty(Context context) {
    File file = new File(context.getCacheDir(), "image");
    return file.getAbsolutePath();
}

From source file:Main.java

public static String getSDCardPath() {
    File path = Environment.getExternalStorageDirectory();
    return path.getAbsolutePath();
}

From source file:Main.java

public static String relative(final File base, final File file) {
    final int rootLength = base.getAbsolutePath().length();
    final String absFileName = file.getAbsolutePath();
    final String relFileName = absFileName.substring(rootLength + 1);
    return relFileName;
}

From source file:Main.java

public static void debugLsDir(String dir) {
    File directory = new File(dir);
    Log.d("quran_dbg", directory.getAbsolutePath());

    if (directory.isDirectory()) {
        String[] children = directory.list();
        for (String s : children)
            debugLsDir(dir + File.separator + s);
    }/*from w  w w .j  a  v a  2s .  co  m*/
}