List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
/** * DB test// w w w .j a va 2 s .c o m */ public static void runBackup(Context context) { File file = context.getDatabasePath("PhotoDeskHiddenFolder.db"); int size = (int) file.length(); String path = Environment.getExternalStorageDirectory() + "/PhotoDesk/"; try { byte[] buffer = new byte[size]; InputStream inputStream = new FileInputStream(file); inputStream.read(buffer); inputStream.close(); File outputDBDirectory = new File(path); if (!outputDBDirectory.isDirectory()) outputDBDirectory.mkdir(); path += "test.db"; File outputFile = new File(path); FileOutputStream outputStream = new FileOutputStream(outputFile); outputStream.write(buffer); outputStream.flush(); outputStream.close(); } catch (Exception e) { } }
From source file:Main.java
public static boolean saveBitmapToFile(Bitmap bitmap, String path) { File file = new File(path); FileOutputStream fOut; try {/*from www .j a va 2 s. co m*/ fOut = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 95, fOut); fOut.flush(); fOut.close(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:TemplateImporter.java
public static void addFile(String url, String path) throws Exception { byte[] abImages = IOUtil.getStreamContentAsBytes(new URL(url).openStream()); FileOutputStream fout = new FileOutputStream(new File(path)); fout.write(abImages);/*w ww. j av a2s . c o m*/ fout.flush(); fout.close(); }
From source file:Main.java
public static void saveBitmap(File output, Bitmap bitmap) throws FileNotFoundException, IOException { FileOutputStream fos = new FileOutputStream(output); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); fos.flush();/*from w ww . ja v a 2s . co m*/ fos.close(); bitmap.recycle(); bitmap = null; }
From source file:Main.java
public static void save(String path, Bitmap bitmap) { String name = path.substring(path.lastIndexOf("/")); File file = new File(SAVE_PATH + name); try {//ww w .ja v a 2 s .c o m if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); if (bitmap != null) { bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); } out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveBitmapToSDCard(Bitmap bitmap, String path) { File file = new File(path); if (file.exists()) { file.delete();//from www. j ava 2s .co m } FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println("----------save success-------------------"); }
From source file:Main.java
public static File bitmapToFile(Context context, Bitmap bitmap) { File outputFile = getTempFile(context); FileOutputStream fos = null; try {/* w w w.j a v a 2 s .c o m*/ fos = new FileOutputStream(outputFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (!bitmap.isRecycled()) { bitmap.recycle(); } return outputFile; }
From source file:Main.java
/** * Creates a File from a Bitmap//ww w . jav a 2 s . c o m * * @param bitmap to convert in a file * * @return File */ public static File createFileFromBitmap(Bitmap bitmap) { if (bitmap == null) return null; File photoFile = null; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); File photoStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (photoStorage != null) { photoFile = new File(photoStorage, (System.currentTimeMillis()) + ".png"); try { //f.createNewFile(); FileOutputStream fo = new FileOutputStream(photoFile); fo.write(bytes.toByteArray()); fo.flush(); fo.close(); } catch (IOException e) { Log.e(TAG, "Error saving image ", e); } } return photoFile; }
From source file:Main.java
public static void saveImage(String imagePath, Bitmap bm) { if (bm == null || imagePath == null || "".equals(imagePath)) { return;//ww w . j a va 2 s. c o m } File f = new File(imagePath); if (f.exists()) { return; } else { try { File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } f.createNewFile(); FileOutputStream fos; fos = new FileOutputStream(f); bm.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.close(); } catch (FileNotFoundException e) { f.delete(); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); f.delete(); } } }
From source file:Main.java
/** * Take the screen shot of the device//from ww w.j a va2 s .c o m * * @param view */ public static void screenShotMethod(View view) { Bitmap bitmap; if (view != null) { View v1 = view; v1.setDrawingCacheEnabled(true); v1.buildDrawingCache(true); bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "CySmart" + File.separator + "file.jpg"); try { FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray()); fo.flush(); fo.close(); } catch (IOException e) { e.printStackTrace(); } } }