List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static void saveBitmapToCacheDir(Context context, Bitmap bitmap, String name) { try {/* w w w. j a v a 2s.c om*/ File file = new File(context.getCacheDir(), name); if (file.exists()) { file.delete(); } FileOutputStream fos = context.openFileOutput(name, MODE_PRIVATE); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveAccount(Activity act, String account, String psw) { String str = account + "," + psw; Properties localProperties = new Properties(); localProperties.put("account", str); try {/*from ww w.j ava2 s . co m*/ File file = new File(act.getFilesDir() + "/accout.cfg"); if (!file.exists()) file.createNewFile(); FileOutputStream localFileOutputStream = act.openFileOutput("account.cfg", Context.MODE_PRIVATE); localProperties.store(localFileOutputStream, ""); localFileOutputStream.close(); } catch (Exception localException) { localException.printStackTrace(); } }
From source file:asia.gkc.vneedu.utils.FileUtil.java
/** * ?//from ww w . j a v a2 s. c o m * * @param bytes - ? * @param destination - * @return * @throws IOException */ public static boolean transferFile(byte[] bytes, File destination) throws IOException { FileOutputStream fos = new FileOutputStream(destination); fos.write(bytes); fos.close(); return true; }
From source file:Main.java
public static void saveDomSource(final DOMSource source, final File target, final File xslt) throws TransformerException, IOException { TransformerFactory transFact = TransformerFactory.newInstance(); transFact.setAttribute("indent-number", 2); Transformer trans;// w ww. j a v a2s . co m if (xslt == null) { trans = transFact.newTransformer(); } else { trans = transFact.newTransformer(new StreamSource(xslt)); } trans.setOutputProperty(OutputKeys.INDENT, "yes"); FileOutputStream fos = new FileOutputStream(target); trans.transform(source, new StreamResult(new OutputStreamWriter(fos, "UTF-8"))); fos.close(); }
From source file:Main.java
public static void write(Context context, String fileName, String content) { if (content == null) content = ""; try {//ww w .j a va 2s .co m FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); fos.write(content.getBytes()); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.ptlug.ptwifiauth.Utilities.java
public static boolean saveUserToSdCard(String user, String password) { try {// w ww. j a v a2 s . com File file = new File(AppConsts.file_path, AppConsts.user_file); FileOutputStream fos = new FileOutputStream(file); fos.flush(); fos.close(); } catch (Exception e) { return false; } return true; }
From source file:Main.java
public static void saveObj(String fileName, Object obj) { try {//from ww w . j a v a 2s .c o m FileOutputStream fout = new FileOutputStream(fileName); ObjectOutputStream oout = new ObjectOutputStream(fout); oout.writeObject(obj); fout.close(); oout.close(); } catch (Exception e) { printE("OpusTool", e); } }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String path) { try {/*from w w w . ja v a 2 s . c om*/ FileOutputStream out = new FileOutputStream(path); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveBitmap(Bitmap bm, String picName) { try {/* ww w . j av a 2 s .c o m*/ if (!isFileExist("")) { createSDDir(""); } File f = new File(SDPATH, picName); if (f.exists()) { f.delete(); } FileOutputStream out = new FileOutputStream(f); bm.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
/** * Write image to internal storage//from w w w. j ava2 s . c o m * @param context : Context android. * @param fileName : Image file name. * @param image : Bitmap image format PNG only. */ public static void saveImageToInternalStorage(Context context, String fileName, Bitmap image) { // Convert Bitmap to byteArray ByteArrayOutputStream stream = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); // Open fileOutput with fileName and write byteArray try { FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); if (fos != null) { fos.write(byteArray); fos.close(); } } catch (Exception e) { e.printStackTrace(); } }