List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static File convertBase64IntoFile(String base64, String path) { File dwldsPath = new File(path); byte[] pdfAsBytes = convertBase64IntoByte(base64); FileOutputStream os; try {/*from ww w. ja va2 s . c om*/ os = new FileOutputStream(dwldsPath, false); os.write(pdfAsBytes); os.flush(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return dwldsPath; }
From source file:net.bioclipse.model.ImageWriter.java
public static void saveImagePNG(String path, JFreeChart chart) throws IOException { FileOutputStream fos = new FileOutputStream(path); ChartUtilities.writeChartAsPNG(fos, chart, 640, 480); fos.close(); }
From source file:Main.java
public static void saveImage(Bitmap bmp) { String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/abcxyz"); myDir.mkdirs();// w w w . j a v a 2s . co m Random generator = new Random(); int n = 10000; n = generator.nextInt(n); String name = "Image-" + n + ".jpg"; File file = new File(myDir, name); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); bmp.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 getWordDocument1(ByteArrayOutputStream recvstram, String filename, String xslfilename) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError { try {//w w w . j a va2 s . c o m byte[] myBytes = recvstram.toByteArray(); FileOutputStream out = new FileOutputStream("g:/input.txt"); try { out.write(myBytes); } finally { out.close(); } (TransformerFactory.newInstance().newTransformer(new StreamSource(new File("g:/" + xslfilename)))) .transform(new StreamSource(new File("g:/input.txt")), new StreamResult(new File("g:/channel.doc"))); } catch (Exception e) { } }
From source file:net.bioclipse.model.ImageWriter.java
public static void saveImageJPG(String path, JFreeChart chart) throws IOException { FileOutputStream fos = new FileOutputStream(path); ChartUtilities.writeChartAsJPEG(fos, chart, 640, 480); fos.close(); }
From source file:com.technofovea.packbsp.PackbspUtil.java
/** * Efficiently copies a given file, returning a temporary copy which will be * removed when execution finishes.// w w w . j a v a 2 s. c o m * * @param source Source file to copy. * @return The copied file. * @throws IOException */ public static final File createTempCopy(File source) throws IOException { String ext = FilenameUtils.getExtension(source.getName()); File dest = File.createTempFile("packbsp_temp_", "." + ext); dest.deleteOnExit(); FileInputStream fis = new FileInputStream(source); FileOutputStream fos = new FileOutputStream(dest); IOUtils.copy(fis, fos); fis.close(); fos.close(); return dest; }
From source file:Main.java
public static void saveJPGE_After(Context context, Bitmap bitmap, String path) { File file = new File(context.getExternalCacheDir() + path); try {// w ww . j ava 2 s. c om 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
/** * save private key and public key of a keypair in the directory * * @param dir//w w w . j a va 2 s . c om * @param keyPair * @param name keys will be stored as name_private.key and name_public.key * @throws IOException */ public static void saveKeyPair(File dir, KeyPair keyPair, String name) throws IOException { // Store Public Key. X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(keyPair.getPublic().getEncoded()); FileOutputStream fos = new FileOutputStream(new File(dir, name + "_public.key")); fos.write(x509EncodedKeySpec.getEncoded()); fos.close(); // Store Private Key. PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded()); fos = new FileOutputStream(new File(dir, name + "_private.key")); fos.write(pkcs8EncodedKeySpec.getEncoded()); fos.close(); }
From source file:Main.java
public static void saveBitmap(Bitmap bm, String picName) { try {// w ww. jav a 2s . com if (!isFileExist("")) { File tempf = createSDDir(""); } File f = new File(SDPATH, picName + ".JPEG"); if (f.exists()) { f.delete(); } FileOutputStream out = new FileOutputStream(f); bm.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Write the given bitmap to a file in the external storage. Requires * "android.permission.WRITE_EXTERNAL_STORAGE" permission. *//*www . j a v a 2 s . c om*/ public static void writeToFile(Bitmap bitmap, String dir, String filename) throws FileNotFoundException, IOException { File sdCard = Environment.getExternalStorageDirectory(); File dirFile = new File(sdCard.getAbsolutePath() + "/" + dir); dirFile.mkdirs(); File f = new File(dirFile, filename); FileOutputStream fos = new FileOutputStream(f, false); bitmap.compress(CompressFormat.PNG, 100 /*ignored for PNG*/, fos); fos.flush(); fos.close(); }