List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static boolean saveBitmap(Bitmap bmp, String path) { File file = new File(path); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs();// w w w . jav a2s. c o m } if (file.exists()) { file.delete(); } try { FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 80, out); out.flush(); out.close(); Log.i("saveBitmap success:", path); return true; } catch (Exception e) { Log.e("saveBitmap:" + path, e.toString()); } return false; }
From source file:com.kyon.klib.base.KFileUtils.java
public static void writeFile(Context context, String fileName, String writeStr) throws IOException { try {//from ww w .j a v a2 s.c o m FileOutputStream fOut = context.openFileOutput(fileName, 0); byte[] bytes = writeStr.getBytes(); fOut.write(bytes); fOut.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.scape_project.pc.droid.DroidIdentificationTest.java
/** * Set up./*from w w w . ja v a 2 s. c o m*/ * @throws Exception */ @BeforeClass public static void setUpClass() throws Exception { URL sigFileV67Url = new URL(SIGNATURE_FILE_V67_URL); InputStream sigFileStream = sigFileV67Url.openStream(); File tmpSigFile = File.createTempFile("tmpsigfile", ".xml"); FileOutputStream fos = new FileOutputStream(tmpSigFile); IOUtils.copy(sigFileStream, fos); fos.close(); dihj = DroidIdentification.getInstance(tmpSigFile.getAbsolutePath()); }
From source file:TripleDES.java
/** Save the specified TripleDES SecretKey to the specified file */ public static void writeKey(SecretKey key, File f) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { // Convert the secret key to an array of bytes like this SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede"); DESedeKeySpec keyspec = (DESedeKeySpec) keyfactory.getKeySpec(key, DESedeKeySpec.class); byte[] rawkey = keyspec.getKey(); // Write the raw key to the file FileOutputStream out = new FileOutputStream(f); out.write(rawkey);/*from www .j a va 2 s .c om*/ out.close(); }
From source file:Main.java
public static void storeImage(Bitmap image, String name) { if (DEBUG) {/*from w ww . ja v a 2 s . c om*/ String TAG = "MobileODR"; File pictureFile = getOutputMediaFile(name); if (pictureFile == null) { Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage()); return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); image.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } }
From source file:eu.scape_project.pc.droid.DroidIdentificationTaskTest.java
/** * Set up./*w ww. j a va 2s. c o m*/ * @throws Exception */ @BeforeClass public static void setUpClass() throws Exception { URL sigFileV67Url = new URL(SIGNATURE_FILE_V67_URL); InputStream sigFileStream = sigFileV67Url.openStream(); File tmpSigFile = File.createTempFile("tmpsigfile", ".xml"); FileOutputStream fos = new FileOutputStream(tmpSigFile); IOUtils.copy(sigFileStream, fos); fos.close(); dihj = DroidIdentificationTask.getInstance(tmpSigFile.getAbsolutePath()); }
From source file:Main.java
private static void copyInputStreamToFile(InputStream is, File file) throws Exception { int bytes;/*from w w w .j a v a2s . co m*/ byte[] buf = new byte[BUFFER_SIZE]; FileOutputStream fos = new FileOutputStream(file); while ((bytes = is.read(buf, 0, BUFFER_SIZE)) > 0) { fos.write(buf, 0, bytes); } is.close(); fos.close(); }
From source file:Main.java
public static void logGlobalException(Context c, String[] logs) { String dir = c.getExternalFilesDir(null).getParent(); try {/* w ww.j ava2 s . com*/ File file = new File(dir + "/error_logs.log"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file, true); for (String log : logs) { fos.write((log + "\n\n").getBytes()); } fos.close(); } catch (IOException ioe) { Log.e("AndroidUtils", "An exception has occured in logGlobalException!"); ioe.printStackTrace(); } }
From source file:com.netsteadfast.greenstep.util.PdfConvertUtils.java
@SuppressWarnings("unchecked") public static List<File> toImageFiles(File pdfFile, int resolution) throws Exception { PDDocument document = PDDocument.loadNonSeq(pdfFile, null); List<PDPage> pages = document.getDocumentCatalog().getAllPages(); File tmpDir = new File(Constants.getWorkTmpDir() + "/" + PdfConvertUtils.class.getSimpleName() + "/" + System.currentTimeMillis() + "/"); FileUtils.forceMkdir(tmpDir);//from w w w . j a va 2s . co m List<File> files = new LinkedList<File>(); int len = String.valueOf(pages.size() + 1).length(); for (int i = 0; i < pages.size(); i++) { String name = StringUtils.leftPad(String.valueOf(i + 1), len, "0"); BufferedImage bufImage = pages.get(i).convertToImage(BufferedImage.TYPE_INT_RGB, resolution); File imageFile = new File(tmpDir.getPath() + "/" + name + ".png"); FileOutputStream fos = new FileOutputStream(imageFile); ImageIOUtil.writeImage(bufImage, "png", fos, resolution); fos.flush(); fos.close(); files.add(imageFile); } document.close(); tmpDir = null; return files; }
From source file:Main.java
public static void writeMediaListLastUpdatedTimeToFile(Context context, String listType, String lastUpdatedTime) { // writing to internal private memory FileOutputStream fos = null; try {/* ww w.j a v a 2 s .co m*/ fos = context.openFileOutput(listType, Context.MODE_PRIVATE); fos.write(lastUpdatedTime.getBytes()); fos.close(); Log.v(TAG, "Lastupdated time " + lastUpdatedTime + " successfully written to file for listType = " + listType); } catch (Exception exp) { Log.v(TAG, "Failed to write lastUpdated time. exp:" + exp.getMessage()); exp.printStackTrace(); } }