Created
June 10, 2014 00:29
-
-
Save snadjafi/2bbc12c40bad159e935c to your computer and use it in GitHub Desktop.
app specific directory location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static File createExternalStoragePrivateFile(Context context, byte[] bytes, String fileName) { | |
| deleteExternalStoragePrivateFile(context, fileName); | |
| File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName); | |
| try { | |
| OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); | |
| outputStream.write(bytes); | |
| outputStream.flush(); | |
| outputStream.close(); | |
| } catch (IOException e) { | |
| Timber.w(e, "ExternalStorage", "Error writing " + file + e.getMessage()); | |
| return null; | |
| } | |
| return file; | |
| } | |
| public static void deleteExternalStoragePrivateFile(Context context, String fileName) { | |
| File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName); | |
| if (file != null) { | |
| file.delete(); | |
| } | |
| } | |
| public static boolean hasExternalStoragePrivateFile(Context context, String fileName) { | |
| File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName); | |
| if (file != null) { | |
| return file.exists(); | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment