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 put(String s, String name) {
    try {/*w w w  .j av a 2 s  .  c  o  m*/
        File saveFile = new File(Environment.getExternalStorageDirectory() + "/hhtlog/" + name + ".txt");
        if (!saveFile.exists()) {
            File dir = new File(saveFile.getParent());
            dir.mkdirs();
            saveFile.createNewFile();
        }

        FileOutputStream outStream = new FileOutputStream(saveFile);
        outStream.write(s.getBytes());
        outStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Write the given bitmap into the given file. JPEG is used as the compression format with
 * quality set/*from w w w . j  ava 2s . com*/
 * to 100.
 *
 * @param bm   The bitmap.
 * @param file The file to write the bitmap into.
 */
public static void writeBitmapToFile(Bitmap bm, File file, int quality) throws IOException {

    FileOutputStream fos = new FileOutputStream(file);
    bm.compress(Bitmap.CompressFormat.JPEG, quality, fos);
    fos.flush();
    fos.close();
}

From source file:Main.java

public static void saveToFile(String filename, Bitmap bmp) {
    try {/*  w  w w .j  a  v a  2  s. co  m*/
        FileOutputStream out = new FileOutputStream(filename);
        bmp.compress(CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        Log.d("Exception", e.getMessage());
    }
}

From source file:Main.java

public static void save2File(byte[] content, File file) throws IOException {
    FileOutputStream outStream = new FileOutputStream(file);
    outStream.write(content);//  w  w w  . ja  v a2s.c  o  m
    outStream.flush();
    outStream.close();
}

From source file:Main.java

public static void saveBitmap(String filename, Bitmap bitmap) throws Exception {
    File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename);
    if (file.exists()) {
        file.delete();/*  w  w w  . j av a2  s  .com*/
    }
    file.createNewFile();
    FileOutputStream fos = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
    fos.flush();
    fos.close();
}

From source file:Main.java

public static File getFile(Context context, Bitmap sourceImg) {
    try {/*w  ww .j ava  2 s .c o m*/
        File f = new File(context.getCacheDir(), System.currentTimeMillis() + "temp.jpg");
        f.createNewFile();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        int options = 100;
        sourceImg.compress(Bitmap.CompressFormat.JPEG, options, bos);
        while (bos.toByteArray().length / 1024 > 100) {
            bos.reset();
            options -= 10;
            sourceImg.compress(Bitmap.CompressFormat.JPEG, options, bos);
        }
        byte[] bitmapdata = bos.toByteArray();
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();
        return f;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static File saveBitmap(Bitmap bitmap, String path, String picName) {
    File dir = new File(path);
    if (dir != null && !dir.exists()) {
        dir.mkdirs();/*from ww w.  j a v a  2s.  c om*/
    }
    File file = new File(dir, picName);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return file;
}

From source file:org.apache.camel.example.SpringJmsClientRemotingServerTest.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
    int port = AvailablePortFinder.getNextAvailable();
    String bank1 = "tcp.port=" + port;

    File custom = new File("target/custom.properties");
    FileOutputStream fos = new FileOutputStream(custom);
    fos.write(bank1.getBytes());// w w w . j a v a  2 s.c  o  m
    fos.close();

    appCtx = new ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml",
            "camel-client-remoting.xml");
    appCtx.start();
}

From source file:Main.java

/**
 * Write a string value to the specified file.
 * @param filename      The filename//from w  w w.  ja  v a  2s.  com
 * @param value         The value
 */
public static void writeValue(String filename, String value) {
    try {
        FileOutputStream fos = new FileOutputStream(new File(filename));
        fos.write(value.getBytes());
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void writeSDFile(String fileName, String write_str) throws IOException {
    File file = new File(fileName);

    FileOutputStream fos = new FileOutputStream(file);

    byte[] bytes = write_str.getBytes();

    fos.write(bytes);/*from   www. ja va  2  s.co m*/

    fos.close();
}