Example usage for java.io BufferedWriter flush

List of usage examples for java.io BufferedWriter flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:Main.java

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

    char[] cbuf = "from java2s.com".toCharArray();

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    bw.write(cbuf, 2, 5);//w  w  w  .  ja  v  a  2s.  com

    bw.flush();

    StringBuffer sb = sw.getBuffer();

    System.out.println(sb);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 2000;
    ServerSocket srv = new ServerSocket(port);

    // Wait for connection from client.
    Socket socket = srv.accept();
    BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    wr.write("aString");
    wr.flush();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String multilineString = "This is line 1\nthis is line 2\nthis is last line";

    FileWriter fileWriter = new FileWriter("multiline.txt", true);

    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    bufferedWriter.write(multilineString + "\n");
    bufferedWriter.flush();
    bufferedWriter.close();/*from   w w w.  j a  v  a2s  .  co m*/
    fileWriter.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String strLine = in.readLine();
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    out.write(strLine, 0, strLine.length());
    out.flush();
    in.close();/*from  w  w w .  j  av a 2 s  .  c  o m*/
    out.close();
}

From source file:Main.java

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

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    for (int i = 65; i <= 90; i++) {
        bw.write(i);//from w ww.  j  a  va2  s . c om
    }

    bw.flush();

    StringBuffer sb = sw.getBuffer();

    System.out.println(sb);

}

From source file:Main.java

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

    String letters = "from java2s.com";

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    for (char c : letters.toCharArray()) {

        bw.append(c);/*from   w w  w .j  a  v a  2  s. co m*/

        bw.flush();

        System.out.println(sw.getBuffer());
    }

}

From source file:Main.java

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

    String s = "from java2s.com!";

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    bw.write(s, 0, 5);//from w  ww.  j a  v  a2 s . c  om

    bw.newLine();

    bw.write(s, 6, s.length() - 6);

    bw.flush();

    System.out.print(sw.getBuffer());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream in = System.in;
    BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));

    int letter;//  w  w w  .j a v  a 2s  . com

    while ((letter = in.read()) != -1) {
        bw.write((char) letter);
        bw.flush();
    }
}

From source file:Main.java

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

    String str = "from java2s.com!";

    // create string writer
    StringWriter sw = new StringWriter();

    // create buffered writer
    BufferedWriter bw = new BufferedWriter(sw);

    // writing string to writer
    bw.write(str, 1, 4);/* ww w.  jav  a  2s.  c o m*/

    // forces out the characters to string writer
    bw.flush();

    // string buffer is created
    StringBuffer sb = sw.getBuffer();

    System.out.println(sb);

}

From source file:com.diskoverorta.utils.JsonConvertor.java

public static void main(String[] args) throws IOException {
    JsonConvertor js = new JsonConvertor();
    js.JsonConvertor();/* w  w  w.  ja v a  2 s. co  m*/
    BufferedWriter bf = new BufferedWriter(new FileWriter("/home/serendio/jaroutput-json.txt"));
    bf.write(js.JsonConvertor());
    bf.newLine();
    bf.flush();
    bf.close();
}