List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static void savePic2SD(Bitmap bitmap, String path, String folder) { boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); if (sdCardExist) { File fileDir = new File(folder); if (!fileDir.exists()) { fileDir.mkdir();/*w w w . j a v a2 s. c om*/ } } File file = new File(path); if (file.exists()) { file.delete(); } try { FileOutputStream out = new FileOutputStream(file); if (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 String saveToPrivateFile(Activity activity, String filename, Bitmap bmp) { FileOutputStream fos; try {/*from ww w. jav a 2s . c o m*/ fos = activity.openFileOutput(filename, Context.MODE_PRIVATE); bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.close(); return filename; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } }
From source file:com.redsqirl.workflow.utils.FileStream.java
public static void encryptFile(File in, File out) throws Exception { //Write the encrypted data to a new file: FileOutputStream outStream = new FileOutputStream(out); outStream.write(encryptFile(in));//w w w .j a va 2s . co m outStream.close(); }
From source file:com.redsqirl.workflow.utils.FileStream.java
public static void decryptFile(File in, File out) throws Exception { //Write the encrypted data to a new file: FileOutputStream outStream = new FileOutputStream(out); outStream.write(decryptFile(in));// w w w. ja v a2 s . c o m outStream.close(); }
From source file:Main.java
public static void saveBookmark(String extractPath, String md5, ArrayList<String> listBookmark) { try {//from ww w . j a va 2 s .co m FileOutputStream fos = new FileOutputStream(extractPath + "/bookmark_" + md5, false); for (String str : listBookmark) { fos.write((str + ";").getBytes()); } fos.close(); } catch (IOException ignored) { } }
From source file:Main.java
public static String SaveBitmap(Bitmap bmp, String name) { File file = new File("mnt/sdcard/picture/"); String path = null;//www. j a v a 2 s. c om if (!file.exists()) file.mkdirs(); try { path = file.getPath() + "/" + name; FileOutputStream fileOutputStream = new FileOutputStream(path); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); System.out.println("saveBmp is here"); } catch (Exception e) { e.printStackTrace(); } return path; }
From source file:Main.java
public static Bitmap saveBitmapToFile(Activity activity, Bitmap bitmap) { String mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); File imageFile = new File(mPath); boolean create = imageFile.mkdirs(); boolean canWrite = imageFile.canWrite(); Calendar cal = Calendar.getInstance(); String date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE); String filename = null;//from w w w .ja va 2 s . c o m int i = 0; while (imageFile.exists()) { i++; filename = date + "_mandelbrot" + i + ".png"; imageFile = new File(mPath, filename); boolean canWrite2 = imageFile.canWrite(); } try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); /*resultB*/bitmap.compress(CompressFormat.PNG, 90, bos); byte[] bitmapdata = bos.toByteArray(); //write the bytes in file FileOutputStream fos = new FileOutputStream(imageFile); fos.write(bitmapdata); fos.flush(); fos.close(); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(imageFile)); activity.sendBroadcast(intent); displaySuccesToast(activity); } catch (FileNotFoundException e) { displayFileError(activity); e.printStackTrace(); } catch (IOException e) { displayFileError(activity); e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static void saveJsonToFile(String toSave, String filename, Activity currActivity) { // check if the file exists File dir = currActivity.getFilesDir(); File file = new File(dir, filename); if (file.exists()) { file.delete();//from ww w. j a v a2 s . c o m } FileOutputStream outputStream; try { outputStream = currActivity.openFileOutput(filename, Context.MODE_APPEND); outputStream.write(toSave.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.moz.fiji.mapreduce.TestingResources.java
/** * Writes a text file.//from w ww . j a v a 2 s . c om * * @param path Path of the file to write. * @param content Text content of the file to create. * @throws IOException on I/O error. */ public static void writeTextFile(final File path, final String content) throws IOException { final FileOutputStream ostream = new FileOutputStream(path); try { IOUtils.write(content, ostream); } finally { ostream.close(); } }
From source file:it.nicola_amatucci.util.JsonAndroidLocalIO.java
public static <T> boolean saveData(Context context, String filename, T o, Class<T> obj) { String document = null;/*from w w w .j av a 2 s . c om*/ try { document = Json.json_from_object(o, obj).toString(); if (document != null) { Log.i("TAG", document); FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE); fos.write(document.getBytes()); fos.close(); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }