List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:Main.java
public static void save2File(byte[] content, File file) throws IOException { FileOutputStream outStream = new FileOutputStream(file); outStream.write(content);/*from w w w. ja v a 2 s . c o m*/ outStream.flush(); outStream.close(); }
From source file:Main.java
public static void saveImage(String path, Bitmap bitmap) throws IOException { File file = new File(path); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs();/*from w w w . j a v a2s . co m*/ } FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); }
From source file:Main.java
public static void saveToFile(String filename, Bitmap bmp) { try {/*from www. java 2 s . c o m*/ FileOutputStream out = new FileOutputStream(filename); bmp.compress(CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (Exception e) { Log.d("Exception", e.getMessage()); } }
From source file:Main.java
public static File getFile(Context context, Bitmap sourceImg) { try {/*from www. j a v a 2 s . c o m*/ File f = new File(context.getCacheDir(), System.currentTimeMillis() + "temp.jpg"); f.createNewFile(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int options = 100; sourceImg.compress(Bitmap.CompressFormat.JPEG, options, bos); while (bos.toByteArray().length / 1024 > 100) { bos.reset(); options -= 10; sourceImg.compress(Bitmap.CompressFormat.JPEG, options, bos); } byte[] bitmapdata = bos.toByteArray(); FileOutputStream fos = new FileOutputStream(f); fos.write(bitmapdata); fos.flush(); fos.close(); return f; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Write the given bitmap into the given file. JPEG is used as the compression format with * quality set/*from w w w . j a va2 s. c om*/ * to 100. * * @param bm The bitmap. * @param file The file to write the bitmap into. */ public static void writeBitmapToFile(Bitmap bm, File file, int quality) throws IOException { FileOutputStream fos = new FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, quality, fos); fos.flush(); fos.close(); }
From source file:Main.java
/** * Write a string value to the specified file. * @param filename The filename/*from w w w .j ava 2 s.com*/ * @param value The value */ public static void writeValue(String filename, String value) { try { FileOutputStream fos = new FileOutputStream(new File(filename)); fos.write(value.getBytes()); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveBitmap(String filename, Bitmap bitmap) throws Exception { File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename); if (file.exists()) { file.delete();//from w w w.j av a 2 s .c o m } file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); }
From source file:Main.java
public static String saveToFile(String filename, Bitmap bmp) { try {//w ww . j a va 2 s . co m FileOutputStream out = new FileOutputStream(filename); bmp.compress(CompressFormat.PNG, 100, out); out.flush(); out.close(); return filename; } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static boolean saveDrawabletoFile(Context c, Drawable d, File file) { //create a file to write bitmap data try {/*w w w . ja va 2 s .c om*/ file.createNewFile(); //Convert bitmap to byte array Bitmap bitmap = ((BitmapDrawable) d).getBitmap(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos); byte[] bitmapdata = bos.toByteArray(); //write the bytes in file FileOutputStream fos = new FileOutputStream(file); fos.write(bitmapdata); fos.flush(); fos.close(); return true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:Main.java
public static boolean saveString(String filename, String jsonString) throws Exception { File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename); FileOutputStream fos = new FileOutputStream(file); byte[] buff = jsonString.getBytes(); fos.write(buff);//from w ww .ja va2 s .c om fos.flush(); fos.close(); return true; }