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 int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) {
    int rotate = 0;
    try {//from   w  w w . j  a  v  a 2s .  c  o  m
        context.getContentResolver().notifyChange(imageUri, null);
        File imageFile = new File(imagePath);
        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:com.truebanana.data.SecureDataFile.java

public static SecureDataFile loadFromFile(File file, String password) {
    String filePath = file.getAbsolutePath();
    if (loadedDataFiles.containsKey(filePath)) {
        Log.d("SecureDataFile", "Loading cached data file");
        return loadedDataFiles.get(filePath);
    } else {/*ww w  .  j  a v  a2 s .  c o m*/
        Log.d("SecureDataFile", "Loading data file from disk");
        byte[] data = new byte[0];
        try {
            data = FileUtils.readFileToByteArray(file);
            Log.d("SecureDataFile", "Successfully read data file");
        } catch (IOException e) {
            Log.d("SecureDataFile", "Could not read data file");
        }

        SecureDataFile dataFile = new SecureDataFile(data, file, password);

        loadedDataFiles.put(filePath, dataFile);
        return dataFile;
    }
}

From source file:Main.java

public static Bitmap getImg(String url) {
    if (!isMounted())
        return null;

    File imgFile = new File(CACHEDIR, getName(url));
    if (imgFile.exists()) {
        return BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    }/*from   ww  w.j  a  va 2 s .  c o m*/

    return null;
}

From source file:Main.java

public static boolean saveContentToFile(byte[] content, File fileForSave) {
    ReentrantReadWriteLock.WriteLock writeLock = getLock(fileForSave.getAbsolutePath()).writeLock();
    boolean succeed = true;
    FileOutputStream out = null;// w  ww.j  a v  a  2 s .  c  o  m
    if (writeLock.tryLock()) {
        try {
            out = new FileOutputStream(fileForSave, false);
            out.write(content);
        } catch (Exception var9) {
            //log.d(var9.toString());
            succeed = false;
        } finally {
            if (out != null) {
                closeQuietly(out);
            }

            writeLock.unlock();
        }
    }

    return succeed;
}

From source file:Main.java

public static void writeLifeLogCountInFile(int walking, int running, int vehicle, int bicycle, String filename)
        throws IOException {
    Date date = new Date();
    BufferedWriter writer = null;
    File dir = new File(Environment.getExternalStorageDirectory() + "/LifeLog");
    Log.d("Directory PATH", dir.getAbsolutePath());
    boolean flag = dir.mkdir();
    Log.d("Directory created?", "" + flag);
    File file = new File(dir.getAbsolutePath(), filename);
    if (file.exists() == false) {
        file.createNewFile();//from   ww w.  j a v  a  2s . c  om
        writer = new BufferedWriter(new FileWriter(file, true));
        writer.write("Date,Walking,Running,Bicycle,Vehicle");
        writer.newLine();
        writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle);
        writer.newLine();
    } else {
        writer = new BufferedWriter(new FileWriter(file, true));
        writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle);
        writer.newLine();
        Log.d("Appended", "True");
    }
    writer.flush();
    writer.close();

}

From source file:Main.java

private static Map<Long, String> getFilePathAndModyTime(File file) {
    Map<Long, String> map = new HashMap<Long, String>();
    if (file.isFile()) {
        map.put(file.lastModified(), file.getAbsolutePath());
    } else if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            map.putAll(getFilePathAndModyTime(f));
        }//from   ww w  .ja v a2 s. c  o  m
    }
    return map;
}

From source file:Main.java

public static byte[] readFile(File file) throws IOException {
    if (!file.exists()) {
        throw new IOException("not crete file=" + file.getAbsolutePath());
    }/*from   www.j a v  a  2s  .co m*/
    FileInputStream fileInputStream = null;
    ByteArrayOutputStream byteArrayOutputStream = null;
    try {
        fileInputStream = new FileInputStream(file);
        byteArrayOutputStream = new ByteArrayOutputStream(64);
        int length = 0;
        byte[] buffer = new byte[1024];
        while ((length = fileInputStream.read(buffer)) != -1) {
            byteArrayOutputStream.write(buffer, 0, length);
        }
        return byteArrayOutputStream.toByteArray();
    } finally {
        if (fileInputStream != null) {
            fileInputStream.close();
        }
        if (byteArrayOutputStream != null) {
            byteArrayOutputStream.close();
        }
    }
}

From source file:Main.java

public static void zip(String zipFileName, String[] zipEntries) {

    try (ZipOutputStream zos = new ZipOutputStream(
            new BufferedOutputStream(new FileOutputStream(zipFileName)))) {

        // Set the compression level to best compression
        zos.setLevel(Deflater.BEST_COMPRESSION);

        for (int i = 0; i < zipEntries.length; i++) {
            File entryFile = new File(zipEntries[i]);
            if (!entryFile.exists()) {
                System.out.println("The entry file  " + entryFile.getAbsolutePath() + "  does  not  exist");
                System.out.println("Aborted   processing.");
                return;
            }/*from www.  ja v a 2 s . c o  m*/
            ZipEntry ze = new ZipEntry(zipEntries[i]);
            zos.putNextEntry(ze);
            addEntryContent(zos, zipEntries[i]);
            zos.closeEntry();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String getPicStorePath(Context ctx) {
    File file = ctx.getExternalFilesDir(null);
    if (!file.exists()) {
        file.mkdir();/*from   www  .  ja  v  a2  s.  com*/
    }
    File imageStoreFile = new File(file.getAbsolutePath() + "/mq");
    if (!imageStoreFile.exists()) {
        imageStoreFile.mkdir();
    }
    return imageStoreFile.getAbsolutePath();
}

From source file:exec.examples.IoHelper.java

public static List<String> findAllZips(String dir) {
    List<String> zips = Lists.newLinkedList();
    for (File f : FileUtils.listFiles(new File(dir), new String[] { "zip" }, true)) {
        zips.add(f.getAbsolutePath());
    }/*from w  w w.j  ava  2  s  .  c  om*/
    return zips;
}