List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
private static void writeInstallationFile(File installation) throws IOException { FileOutputStream out = new FileOutputStream(installation); String id = UUID.randomUUID().toString(); out.write(id.getBytes());/*from www . j a v a2s .c o m*/ out.close(); }
From source file:Main.java
public static String saveImg(Bitmap b, String name) throws Exception { String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "QuCai/shareImg/"; File mediaFile = new File(path + File.separator + name + ".jpg"); if (mediaFile.exists()) { mediaFile.delete();// ww w .ja v a 2s . c o m } if (!new File(path).exists()) { new File(path).mkdirs(); } mediaFile.createNewFile(); FileOutputStream fos = new FileOutputStream(mediaFile); b.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); b.recycle(); b = null; System.gc(); return mediaFile.getPath(); }
From source file:Main.java
public static void write(Context context, String fileName, String content) { if (content == null) { content = ""; }/*from ww w .j ava2s .c o m*/ try { FileOutputStream fs = context.openFileOutput(fileName, Context.MODE_PRIVATE); fs.write(content.getBytes()); fs.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static String saveImageToGallery(File file, Bitmap bmp) { if (bmp == null) { Log.e(TAG, "saveImageToGallery: the bitmap is null"); return ""; }// www .ja v a2 s.co m try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } Log.e(TAG, "saveImageToGallery: the path of bmp is " + file.getAbsolutePath()); return file.getAbsolutePath(); }
From source file:Main.java
public static boolean saveImage(Bitmap src, String filepath, CompressFormat format) { boolean rs = false; File file = new File(filepath); try {/*from w w w . j a v a 2 s .c o m*/ FileOutputStream out = new FileOutputStream(file); if (src.compress(format, 100, out)) { out.flush(); } out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return rs; }
From source file:Main.java
public static void copyRAWFile(InputStream inStream, File newfile) { try {//from ww w . j a va 2 s . c o m FileOutputStream fs = new FileOutputStream(newfile); copyRAWFile(inStream, fs); fs.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Write data to file.//from w w w .j a va2s .c o m * * @param fileName * @param message */ public static void write2File(String fileName, String message, boolean append) { try { FileOutputStream outStream = new FileOutputStream(fileName, append); byte[] bytes = message.getBytes(); outStream.write(bytes); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:fr.asso.vieillescharrues.parseurs.TelechargeFichier.java
/** * Mthode statique grant le tlechargement de fichiers * @param url Adresse du fichier//from ww w . ja v a 2 s . c o m * @param fichierDest Nom du ficher en local */ public static void DownloadFromUrl(URL url, String fichierDest) throws IOException { File file; if (fichierDest.endsWith(".jpg")) file = new File(PATH + "images/", fichierDest); else file = new File(PATH, fichierDest); file.getParentFile().mkdirs(); URLConnection ucon = url.openConnection(); try { tailleDistant = ucon.getHeaderFieldInt("Content-Length", 0); //Rcupre le header HTTP Content-Length tailleLocal = (int) file.length(); } catch (Exception e) { e.printStackTrace(); } // Compare les tailles des fichiers if ((tailleDistant == tailleLocal) && (tailleLocal != 0)) return; InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.close(); }
From source file:Main.java
public static void save(Bitmap bitmap, String filepath) { try {/*from www . jav a 2 s . c om*/ FileOutputStream fos = new FileOutputStream(filepath); bitmap.compress(CompressFormat.JPEG, 100, fos); bitmap.recycle(); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } }
From source file:Main.java
/** * @param maxSize unit kb/*from w w w .j a va2 s .co m*/ */ public static boolean compressSizeToFile(Bitmap bitmap, int maxSize, File outFile) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int quality = 100; bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); while (baos.toByteArray().length / 1024.0 > maxSize) { if (quality < 30) { break; } quality -= 20; baos.reset(); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); } try { FileOutputStream fileOutputStream = new FileOutputStream(outFile); fileOutputStream.write(baos.toByteArray()); fileOutputStream.close(); } catch (Exception e) { return false; } return true; }