Example usage for java.io FileOutputStream close

List of usage examples for java.io FileOutputStream close

Introduction

In this page you can find the example usage for java.io FileOutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this file output stream and releases any system resources associated with this stream.

Usage

From source file:Main.java

public static void writeFile(byte[] bytes) throws IOException {
    String apkDir = Environment.getExternalStorageDirectory() + "/download/" + "app.apk";
    java.io.File file = new java.io.File(apkDir);
    FileOutputStream fop = new FileOutputStream(file);
    fop.write(bytes);//from   w ww .ja  v a2  s.c om
    fop.flush();
    fop.close();
}

From source file:Main.java

/**
 * Extract a resource into a real file//from w  ww .  j  a v a 2s. c o  m
 * 
 * @param in typically given as getResources().openRawResource(R.raw.something)
 * @param name of the resulting file
 * @param directory target directory
 * @return the resulting file
 * @throws IOException
 */
public static File extractResource(InputStream in, String filename, File directory) throws IOException {
    int n = in.available();
    byte[] buffer = new byte[n];
    in.read(buffer);
    in.close();
    File file = new File(directory, filename);
    FileOutputStream out = new FileOutputStream(file);
    out.write(buffer);
    out.close();
    return file;
}

From source file:Main.java

public static String decodeToFile(File desFile, String encodedString) {
    try {//  ww w .j av a 2 s .  co m
        byte[] decodeBytes = Base64.decode(encodedString.getBytes(), Base64.NO_WRAP);
        FileOutputStream fos = new FileOutputStream(desFile);
        fos.write(decodeBytes);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public synchronized static void writeCh(String path, String cmd) {
    try {/* ww  w. j a va2  s .c om*/
        cmd = cmd + "\n";
        FileOutputStream out = new FileOutputStream(path, true);
        out.write(cmd.getBytes());
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void saveFile(Context context, String name, String text) throws IOException {
    FileOutputStream fos = context.openFileOutput(name, Context.MODE_PRIVATE);
    fos.write(text.getBytes());/*from  w  w  w. j av a  2 s .co  m*/
    fos.close();
}

From source file:Main.java

public static void writeFile(File f, byte[] bS) throws Exception {

    if (f.isFile() && f.exists()) {
        f.delete();//  w w  w . ja  va  2 s .  co  m
    }

    FileOutputStream fos = new FileOutputStream(f);
    fos.write(bS, 0, bS.length);
    fos.flush();
    fos.close();
}

From source file:Main.java

public static void saveBmpToFile(Bitmap bm, File f) throws FileNotFoundException, IOException {
    if (f.exists()) {
        return;//from   w w  w. j ava 2s . c o  m
    }

    FileOutputStream fos = new FileOutputStream(f);
    bm.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.close();
}

From source file:Main.java

public static void writeBitmapToFile(Bitmap bitmap, File file) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
    byte[] bitmapData = bos.toByteArray();

    //write the bytes in file
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(bitmapData);/*from  ww  w.  j  a  v  a2s.  com*/
    fos.flush();
    fos.close();
}

From source file:Main.java

public static void WriteStringToSD(String fileName, String content) {
    Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    File file = new File(Environment.getExternalStorageDirectory(), fileName);
    try {//from w w  w  . ja v  a2  s  . co m
        FileOutputStream fos = new FileOutputStream(file, true);
        fos.write(content.getBytes());
        fos.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void saveEncodedFile(String encoded, File file) throws Exception {
    byte[] decodedAsBytes = Base64.decode(encoded, Base64.DEFAULT);

    FileOutputStream os = new FileOutputStream(file, true);
    os.write(decodedAsBytes);/*  ww w  .  j a va  2 s. co  m*/
    os.flush();
    os.close();
}