Example usage for java.io BufferedOutputStream close

List of usage examples for java.io BufferedOutputStream close

Introduction

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

Prototype

@Override
public void close() throws IOException 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream(new File("C:/Demo"));
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    bos.write("this is a test".getBytes());
    bos.flush();/*from w  w  w .  j  a  v a2s.  c  om*/
    bos.close();
}

From source file:MainClass.java

public static void main(String args[]) {

    try {/*from w w  w.ja v  a2 s  .c o  m*/

        FileOutputStream fos = new FileOutputStream(args[0]);

        BufferedOutputStream bos = new BufferedOutputStream(fos);

        for (int i = 0; i < 12; i++) {
            bos.write(i);
        }

        bos.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:BufferedOutputStreamDemo.java

public static void main(String args[]) throws Exception {
    FileOutputStream fos = new FileOutputStream(args[0]);

    BufferedOutputStream bos = new BufferedOutputStream(fos);

    // Write 12 bytes to the file
    for (int i = 0; i < 12; i++) {
        bos.write(i);//w  w w . j a  v a  2 s  . c om
    }

    bos.close();
}

From source file:OpenFileByName.java

public static void main(String[] args) throws IOException {
    BufferedReader is = new BufferedReader(new FileReader("myFile.txt"));
    BufferedOutputStream bytesOut = new BufferedOutputStream(new FileOutputStream("bytes.dat"));

    // Code here to read from is, write to bytesOut

    bytesOut.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/Demo.txt");
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    byte b = 66;/*from  w w  w . j a v a  2s . c  om*/
    // write a character represented by ascii 66 i.e. 'B'
    bos.write(b);
    bos.flush();
    bos.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
        Socket sock = new Socket("127.0.0.1", 123456);
        byte[] mybytearray = new byte[1024];
        InputStream is = sock.getInputStream();
        FileOutputStream fos = new FileOutputStream("s.pdf");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int bytesRead = is.read(mybytearray, 0, mybytearray.length);
        bos.write(mybytearray, 0, bytesRead);
        bos.close();
        sock.close();// w  ww  .ja  v a 2s .co  m
    }

From source file:PrintFile.java

public static void main(String args[]) throws Exception {
    if (args.length != 2) {
        System.err.println("usage : java PrintFile port file");
        System.err.println("sample: java PrintFile LPT1 sample.prn");
        System.exit(-1);/*w  w w .j a  v  a  2 s  . c o  m*/
    }

    String portname = args[0];
    String filename = args[1];

    // Get port
    CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portname);

    // Open port
    // Requires owner name and timeout
    CommPort port = portId.open("Java Printing", 30000);

    // Setup reading from file
    FileInputStream fis = new FileInputStream(filename);
    BufferedInputStream bis = new BufferedInputStream(fis);

    // Setup output
    OutputStream os = port.getOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(os);

    int c;
    while ((c = bis.read()) != -1) {
        bos.write(c);
    }

    // Close
    bos.close();
    bis.close();
    port.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(new FileOutputStream("yourFile.txt"));
    bufferedOutput.write("Line one".getBytes());
    bufferedOutput.write("\n".getBytes());

    bufferedOutput.write(65);// w  ww  .j  a v  a 2  s. co  m
    bufferedOutput.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(fromFileName));
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(toFileName));
    byte[] buff = new byte[32 * 1024];
    int len;//from w  w w . j  a  v a 2 s. c o m
    while ((len = in.read(buff)) > 0)
        out.write(buff, 0, len);
    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedInputStream fin = new BufferedInputStream(new FileInputStream("in.dat"));
    BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream("out.dat"));
    int i;/* w w w  . j av  a  2s.  co  m*/
    do {
        i = fin.read();
        if (i != -1)
            fout.write(i);
    } while (i != -1);
    fin.close();
    fout.close();
}