Example usage for java.io FileOutputStream flush

List of usage examples for java.io FileOutputStream flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte b = 66;//  w ww. j a  va2  s.  c o  m
    int i = 0;
    FileOutputStream fos = new FileOutputStream("C://test.txt");

    fos.write(b);

    fos.flush();

    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileOutputStream os = new FileOutputStream("outfilename");
    FileDescriptor fd = os.getFD();
    os.write(1);/* w w  w.  j  a  v a  2 s .  c  om*/
    os.flush();
    fd.sync();
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte b = 66;/*from   w w  w  .  j a v a2  s .  c om*/
    int i = 0;
    FileOutputStream fos = new FileOutputStream("C://test.txt", true);

    fos.write(b);

    fos.flush();

    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileOutputStream os = new FileOutputStream("outfilename");
    FileDescriptor fd = os.getFD();
    os.write(1);/*w  ww  .j av  a2 s .  com*/
    os.flush();
    fd.valid();
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte b = 66;/*from www. j  a  v a  2s. com*/
    int i = 0;
    FileOutputStream fos = new FileOutputStream(FileDescriptor.out);

    fos.write(b);

    fos.flush();

    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }
    fos.close();
    fis.close();
}

From source file:FileSplitter.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);
    int size = 1024;
    byte buffer[] = new byte[size];

    int count = 0;
    while (true) {
        int i = fis.read(buffer, 0, size);
        if (i == -1)
            break;

        String filename = args[1] + count;
        FileOutputStream fos = new FileOutputStream(filename);
        fos.write(buffer, 0, i);/*  w w w .  ja  va 2  s  . co m*/
        fos.flush();
        fos.close();

        ++count;
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte b = 66;//  ww  w.  ja  v a  2 s.  com
    int i = 0;
    FileOutputStream fos = new FileOutputStream(new File("C://test1.txt"));

    fos.write(b);

    fos.flush();

    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }
    fos.close();
    fis.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte b = 66;/*w  w  w .  j  ava2  s .  com*/
    int i = 0;
    FileOutputStream fos = new FileOutputStream(new File("C://test1.txt"), true);

    fos.write(b);

    fos.flush();

    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }
    fos.close();
    fis.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com/binary.dat");
    URLConnection uc = u.openConnection();
    String contentType = uc.getContentType();
    int contentLength = uc.getContentLength();
    if (contentType.startsWith("text/") || contentLength == -1) {
        throw new IOException("This is not a binary file.");
    }//  w w w . jav a2 s . c  o m
    InputStream raw = uc.getInputStream();
    InputStream in = new BufferedInputStream(raw);
    byte[] data = new byte[contentLength];
    int bytesRead = 0;
    int offset = 0;
    while (offset < contentLength) {
        bytesRead = in.read(data, offset, data.length - offset);
        if (bytesRead == -1)
            break;
        offset += bytesRead;
    }
    in.close();

    if (offset != contentLength) {
        throw new IOException("Only read " + offset + " bytes; Expected " + contentLength + " bytes");
    }

    String filename = u.getFile().substring(filename.lastIndexOf('/') + 1);
    FileOutputStream out = new FileOutputStream(filename);
    out.write(data);
    out.flush();
    out.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    int howMany = 20;
    // To avoid resizing the buffer, calculate the size of the
    // byte array in advance.
    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
        dout.writeInt(i);//w  ww  . j  a  va 2s . com
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
        bout.writeTo(fout);
        fout.flush();
    } finally {
        fout.close();
    }
}