List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:Main.java
public static boolean saveImage(Bitmap src, String filepath, CompressFormat format) { boolean rs = false; File file = new File(filepath); try {//w w w.ja v a2s .co m FileOutputStream out = new FileOutputStream(file); if (src.compress(format, 100, out)) { out.flush(); } out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return rs; }
From source file:Main.java
public static boolean writeImage(File file, Bitmap mBitmap) { try {/*from ww w . jav a 2 s . c om*/ FileOutputStream fo = new FileOutputStream(file); mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fo); fo.flush(); fo.close(); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); return false; } return true; }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, Bitmap.CompressFormat format, File target) { if (target.exists()) { target.delete();//from w ww . j av a 2 s . c o m } try { FileOutputStream out = new FileOutputStream(target); bitmap.compress(format, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static String saveToLocal(Bitmap bm) { String path = "/sdcard/test.jpg"; try {//from w w w. j a v a2 s. c om FileOutputStream fos = new FileOutputStream(path); bm.compress(CompressFormat.JPEG, 75, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } return path; }
From source file:Main.java
/** * Writes the given value into the given file * * @return true on success, false on failure *///w ww .j av a 2s. c o m public static boolean writeLine(String fileName, String value) { try { FileOutputStream fos = new FileOutputStream(fileName); fos.write(value.getBytes()); fos.flush(); fos.close(); } catch (IOException e) { Log.e(TAG, "Could not write to file " + fileName, e); return false; } return true; }
From source file:Main.java
public static boolean saveFile(Bitmap bitmap, String filename) { File sd = Environment.getExternalStorageDirectory(); File dest = new File(sd, filename); try {// ww w.ja v a 2 s .c o m FileOutputStream out = new FileOutputStream(dest); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String filePath) { File f = new File(filePath); if (f.exists()) { return;//from w w w . j a va 2 s.c om } try { FileOutputStream out = new FileOutputStream(f); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveImage(String imagePath, byte[] buffer) throws IOException { File f = new File(imagePath); if (f.exists()) { return;/*from ww w. j ava 2 s. c o m*/ } else { File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } f.createNewFile(); FileOutputStream fos = new FileOutputStream(imagePath); fos.write(buffer); fos.flush(); fos.close(); } }
From source file:Main.java
public static String saveImageToGallery(File file, Bitmap bmp) { if (bmp == null) { Log.e(TAG, "saveImageToGallery: the bitmap is null"); return ""; }/*from www . java 2 s . c o m*/ try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } Log.e(TAG, "saveImageToGallery: the path of bmp is " + file.getAbsolutePath()); return file.getAbsolutePath(); }
From source file:Main.java
public static boolean delete(File file) { file.setWritable(true);/*from ww w . j av a 2 s.c om*/ try { if (!file.delete()) { FileOutputStream fos = new FileOutputStream(file); fos.write(0); fos.flush(); fos.close(); } Log.d("delete", "Deleted file: " + file + " successfully"); return true; } catch (IOException e) { Log.d("delete", "The deleting file: " + file + " is not successfully", e); return false; } }