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 boolean writeBmpToSDCard(Bitmap bmp, File file, int quality) {
    try {//  ww  w  . j  a v a 2 s  . co  m
        ByteArrayOutputStream baosm = new ByteArrayOutputStream();
        if (file.getPath().toLowerCase(Locale.getDefault()).endsWith(".png")) {
            bmp.compress(Bitmap.CompressFormat.PNG, quality, baosm);
        } else {
            bmp.compress(Bitmap.CompressFormat.JPEG, quality, baosm);
        }
        byte[] bts = baosm.toByteArray();

        if (file.exists()) {
            file.delete();
        }
        file.createNewFile();

        File tempFile = new File(file.getPath() + ".png");

        FileOutputStream fosm = new FileOutputStream(tempFile);
        BufferedOutputStream bos = new BufferedOutputStream(fosm);
        bos.write(bts);
        bos.flush();
        bos.close();
        fosm.close();

        tempFile.renameTo(file);

        return true;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static File getStoragePath(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File externalStorage = context.getExternalFilesDir(null);
        if (externalStorage == null)
            return null;
        return new File(externalStorage.getPath() + File.separatorChar + "storage");
    }/*from w  ww .  j a  v a 2s  .com*/

    return null;
}

From source file:edu.kit.cockpit.valuationserver.sfmpersistency.FileUtil.java

/**
 * checks file for reading//  ww w . j  a  v  a2s.c  o m
 * 
 * @param modelFile
 * @param modelFileName
 */
public static void checkFileForReading(File file) throws IOException {
    if (!file.exists()) {
        String error = "File '" + file.getPath() + "' does not exist";
        log.error(error);
        throw new IOException(error);
    }
}

From source file:ImageUtil.java

/**
 * get fixing preview image rsize <br/>
 * Exif not apply: calculate by formula: iHeight/iWidth*rsize < (lbHeight-10)
 * Exif apply: calculate by formula: iHeight/iWidth*rsize < (lbHeight-80-10)
 * @param imageFile//from   ww  w  . j  a v  a2 s  . co  m
 * @param lbWidth
 * @param lbHeight
 * @param applyExif
 * @return
 */
public static int getFixedPreviewSize(File imageFile, int lbHeight, boolean applyExif) {
    int rsize = 0;
    ImageIcon image = new ImageIcon(imageFile.getPath());
    int iHeight = image.getIconHeight();
    int iWidth = image.getIconWidth();
    image = null;
    if (iHeight > iWidth) {
        if (!applyExif) {
            rsize = lbHeight - 10;
        } else {
            rsize = lbHeight - 90;
        }
    } else {
        if (!applyExif) {
            rsize = (lbHeight - 10) * iWidth / iHeight;
        } else {
            rsize = (lbHeight - 90) * iWidth / iHeight;
        }
    }
    return rsize;
}

From source file:Main.java

/**
 * Check how much usable space is available at a given path.
 * /*from w w w. j a v  a  2  s.  c o  m*/
 * @param path
 *            The path to check
 * @return The space available in bytes
 */
public static long getUsableSpace(File path) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:Main.java

public static void UpdateAnimationFromPath(String sFromPath) {
    String sTmpZipFile = "/data/local/tmp/z4res.zip";
    String sOrgZipFile = "/system/framework/framework-res.apk";
    try {/*from w  w w .  j  av  a 2 s  .  co m*/
        RunRootCmd("busybox cp " + sOrgZipFile + " " + sTmpZipFile);
        File fNewZipFile = UpdateZipFromPath(sTmpZipFile, sFromPath);
        RunSystemCmd("busybox cp " + fNewZipFile.getPath() + " " + sOrgZipFile + "; busybox rm " + sTmpZipFile);
        fNewZipFile.delete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ai.grakn.migration.owl.Main.java

public static void runOwl(MigrationCLI cli) {

    String owlFilename = cli.getRequiredOption("input", "Please specify owl file with the -i option.");

    File owlfile = new File(owlFilename);
    if (!owlfile.exists())
        cli.die("Cannot find file: " + owlFilename);

    cli.printInitMessage(owlfile.getPath());

    OWLMigrator migrator = new OWLMigrator();
    try {/*from ww w. java2 s  .  c o  m*/
        migrator.graph(cli.getGraph())
                .ontology(OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(owlfile))
                .migrate();

        cli.printWholeCompletionMessage();
    } catch (Throwable t) {
        cli.die(t);
    } finally {
        if (migrator.graph() != null)
            migrator.graph().close();
    }

    cli.initiateShutdown();
}

From source file:Main.java

public static String SaveBitmap(Bitmap bmp, String name) {
    File file = new File("mnt/sdcard/picture/");
    String path = null;/*from  ww w .j  ava  2 s .c o m*/
    if (!file.exists())
        file.mkdirs();
    try {
        path = file.getPath() + "/" + name;
        FileOutputStream fileOutputStream = new FileOutputStream(path);

        bmp.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
        System.out.println("saveBmp is here");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return path;
}

From source file:Main.java

private static String getDirPath(Context context) {
    String dirPath = "";
    File photoDir = null;/*from  ww w .j  a v a2  s.  c  om*/
    File extStorageDir = Environment.getExternalStorageDirectory();
    if (extStorageDir.canWrite()) {
        photoDir = new File(extStorageDir.getPath() + "/" + context.getPackageName());
    }
    if (photoDir != null) {
        if (!photoDir.exists()) {
            photoDir.mkdirs();
        }
        if (photoDir.canWrite()) {
            dirPath = photoDir.getPath();
        }
    }
    return dirPath;
}

From source file:Main.java

public static String getExternalRootDirectory(Context context) {
    if (databaseFolder == null) {
        //The location of the temp internal database used for sync should be
        //in the cache, since it is only needed for <1min at a time, and
        //created every time it is needed
        if (useSAF()) {
            File basePath = new File(
                    context.getCacheDir() + File.separator + "externalDatabaseSync" + File.separator);
            databaseFolder = basePath.getPath();
        } else {/*w  w w  .  j  a v a2 s. c o  m*/
            return "/storage/usbdisk0/WildRank/cblite";
        }
    }
    return databaseFolder;
}