List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static boolean saveString(String filename, String jsonString) throws Exception { File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename); FileOutputStream fos = new FileOutputStream(file); byte[] buff = jsonString.getBytes(); fos.write(buff);//from www . j a v a2 s .c om fos.flush(); fos.close(); return true; }
From source file:Main.java
public static File savePictureInGallery(String albumName, String prefix, byte[] fileBytes) { Log.d(TAG, "[AirImagePickerUtils] Entering didSavePictureInGallery"); long current = System.currentTimeMillis(); // Save image to album File folder = getAlbumFolder(albumName); File picture = new File(folder, prefix + "_" + current); // Write Image to File try {// w ww .j av a2 s. c o m FileOutputStream stream = new FileOutputStream(picture); stream.write(fileBytes); stream.close(); } catch (Exception exception) { Log.d(TAG, "[AirImagePickerUtils] exception = " + exception.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (failed)"); return null; } Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (succeeded)"); return picture; }
From source file:org.apache.camel.example.osgi.RmiTest.java
@BeforeClass public static void setupFreePort() throws Exception { // find a free port number, and write that in the custom.properties file // which we will use for the unit tests, to avoid port number in use problems port = AvailablePortFinder.getNextAvailable(); String s = "port=" + port; File custom = new File("target/custom.properties"); FileOutputStream fos = new FileOutputStream(custom); fos.write(s.getBytes());/* w w w . j a va2s . c o m*/ fos.close(); }
From source file:Main.java
/*** * write a line to the log file/*from w w w . ja v a 2 s .co m*/ * * @param line */ public static void writeToLog(String line) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); File f = new File(Environment.getExternalStorageDirectory() + File.separator + folderName); boolean success = true; if (!f.exists()) { success = f.mkdir(); } if (success) { // Do something on success File fileDir = new File(f, dateFormat.format(date) + ".txt"); try { FileOutputStream os = new FileOutputStream(fileDir, true); os.write(line.getBytes()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Main.java
public static void doSerialize(Document d, File f) throws TransformerException, IOException { Transformer t = tf.newTransformer(); FileOutputStream fos = new FileOutputStream(f); StreamResult sr = new StreamResult(fos); t.transform(new DOMSource(d), sr); fos.close(); }
From source file:Main.java
public static void createFile(File file, int numBytes) throws IOException { File parentFile = file.getParentFile(); if (parentFile != null) { parentFile.mkdirs();//from ww w . j ava 2 s . c om } byte[] buffer = new byte[numBytes]; FileOutputStream output = new FileOutputStream(file); try { output.write(buffer); } finally { output.close(); } }
From source file:Main.java
public static String saveToFile(String filename, Bitmap bmp) { try {/*from www . ja va 2 s . c o m*/ FileOutputStream out = new FileOutputStream(filename); bmp.compress(CompressFormat.PNG, 100, out); out.flush(); out.close(); return filename; } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static void writeFileSdcard(String filePath, String content, boolean isAppend) { try {//from ww w.jav a2s .c o m FileOutputStream fout = new FileOutputStream(filePath, isAppend); byte[] bytes = content.getBytes(); fout.write(bytes); fout.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveNamedFile(String patch, String data, String name) { try {//from w w w . j ava 2 s . co m File direct = new File(patch); if (!direct.exists()) direct.mkdirs(); File f = new File(patch + "/" + name); if (!f.exists()) f.createNewFile(); FileOutputStream fos = new FileOutputStream(f); String s = data; fos.write(s.getBytes("UTF-8")); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } }
From source file:Main.java
public static boolean saveDrawabletoFile(Context c, Drawable d, File file) { //create a file to write bitmap data try {/*from w ww. ja v a2 s. co m*/ file.createNewFile(); //Convert bitmap to byte array Bitmap bitmap = ((BitmapDrawable) d).getBitmap(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos); byte[] bitmapdata = bos.toByteArray(); //write the bytes in file FileOutputStream fos = new FileOutputStream(file); fos.write(bitmapdata); fos.flush(); fos.close(); return true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }