List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static boolean bitmapToFile(Bitmap bmp, String fileName) { try {/*ww w.ja va2 s .c o m*/ FileOutputStream out = new FileOutputStream(fileName); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); File iconFile = new File(fileName); iconFile.setReadable(true, false); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:Main.java
/** * Given a byte array of content, writes it to a temporary file and then * returns the path to it as a URL/* www . j av a2s .co m*/ * @param contents The content of the file * @param type The file extension to use * @throws IOException if an error occurs */ public static URL stringToTempFile(byte[] contents, String type) throws IOException { // Make sure we have a temp directory checkForTempDirectory(); // Generate a random file name and keep doing it until we get a unique one File f = null; String fName = null; do { fName = tempDirectory + File.separator + ((int) (Math.random() * 10000000)) + "." + type; f = new File(fName); } while (f.exists()); System.out.println("TEMP: Creating temp file " + fName); FileOutputStream out = new FileOutputStream(f); out.write(contents); out.close(); // Remember this file for later deletion tempFileList.add(fName); return new URL("file://" + fName); }
From source file:Main.java
public static void compressWithQuality(Bitmap image, String outPath, int maxSize) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 20, os); while (os.toByteArray().length / 1024 > 1024) { os.reset();/*w ww.j ava 2 s. co m*/ image.compress(Bitmap.CompressFormat.JPEG, 20, os); } ByteArrayInputStream bi = new ByteArrayInputStream(os.toByteArray()); BitmapFactory.decodeStream(bi); FileOutputStream fi = new FileOutputStream(outPath); fi.write(os.toByteArray()); fi.flush(); fi.close(); }
From source file:Main.java
public static File save2File(String savePath, String saveName, String crashReport) { try {// ww w .j ava 2 s. c o m File dir = new File(savePath); if (!dir.exists()) dir.mkdir(); File file = new File(dir, saveName); FileOutputStream fos = new FileOutputStream(file); fos.write(crashReport.toString().getBytes()); fos.close(); return file; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void saveHistory(String extractPath, String md5, int index) { try {// w w w .j a va2s . c o m FileOutputStream fos = new FileOutputStream(extractPath + "/history_" + md5, false); fos.write(("" + index).getBytes()); fos.close(); } catch (IOException ignored) { } }
From source file:Main.java
public static void bitmap2file(Bitmap bitmap, String path) { try {//w ww . j a v a 2 s . c o m // create a file to write bitmap data File f = new File(path); if (f.exists()) { f.delete(); f.createNewFile(); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 30 /* ignored for PNG */, bos); byte[] bitmapdata = bos.toByteArray(); // write the bytes in file FileOutputStream fos = new FileOutputStream(f); fos.write(bitmapdata); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.aqnote.shared.cryptology.cert.util.PrivateKeyFileUtil.java
public static void writeKeyFile(String b64Key, String keyfile) throws IOException { if (StringUtils.isBlank(b64Key) || StringUtils.isBlank(keyfile)) { return;/*from w w w. jav a 2s . co m*/ } FileOutputStream fos2 = new FileOutputStream(keyfile); fos2.write(b64Key.getBytes()); fos2.flush(); fos2.close(); }
From source file:Main.java
public static void writeToFile(String fileName, byte[] content) { File f = new File(fileName); if (!f.exists()) { try {// ww w. j a v a 2 s.c om f.createNewFile(); } catch (Exception e) { } } try { FileOutputStream opt = new FileOutputStream(f, false); opt.write(content, 0, content.length); opt.close(); } catch (Exception e) { } }
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 ww w. j av a 2 s . c om*/ } FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); }
From source file:Main.java
public static String writeBitmap(byte[] data) throws IOException { File file = new File(Environment.getExternalStorageDirectory() + "/bookclip/"); file.mkdir();//from www.j av a 2s .c o m String bitmapPath = file.getPath() + "/" + System.currentTimeMillis() + ".jpg"; FileOutputStream outStream = new FileOutputStream(bitmapPath); outStream.write(data); outStream.close(); return bitmapPath; }