public static void copyFile(File sourceFile, File destinationFile) { try { FileInputStream fileInputStream = null; FileOutputStream fileOutputStream = null; // Inner try block is for streams and readers that needs closing. try { fileInputStream = new FileInputStream(sourceFile); fileOutputStream = new FileOutputStream(destinationFile); byte[] buffer = new byte[1024]; int length = 0; while ((length = fileInputStream.read(buffer)) != -1) { fileOutputStream.write(buffer, 0, length); } } finally { if (fileInputStream != null) fileInputStream.close(); if (fileOutputStream != null) fileOutputStream.close(); } } catch (Throwable throwable) { App.e(FileUtilities.class, throwable); } }
public static Bitmap getBitmapFromFile(File imageFile) { try { return BitmapFactory.decodeFile(imageFile.getPath()); } catch (Exception exception) { App.e(FileUtilities.class, exception); } return null; }
public static Bitmap getBitmapFromStream(InputStream inputStream) { try { return BitmapFactory.decodeStream(inputStream); } catch (Exception exception) { App.e(FileUtilities.class, exception); } return null; }
public static Bitmap getBitmapFromResource(Context context, int drawable) { try { return BitmapFactory.decodeResource(context.getResources(), drawable); } catch (Exception exception) { App.e(FileUtilities.class, exception); } return null; }
public static Drawable getDrawableFromResource(Context context, int drawable) { try { return context.getResources().getDrawable(drawable); } catch (Exception exception) { App.e(FileUtilities.class, exception); } return null; }