Example usage for java.io PrintWriter flush

List of usage examples for java.io PrintWriter flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:SSLSimpleClient.java

public static void main(String[] args) throws Exception {
    SocketFactory sf = SSLSocketFactory.getDefault();
    Socket s = sf.createSocket(args[0], Integer.parseInt(args[1]));

    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    PrintWriter pw = new PrintWriter(s.getOutputStream());
    pw.println("from java2s.");
    pw.flush();
    System.out.println(br.readLine());
    s.close();//from w w  w. j a  v a  2  s  . c o m
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    SocketFactory factory = SSLSocketFactory.getDefault();
    Socket socket = factory.createSocket("127.0.0.1", 8080);

    OutputStream outputStream = socket.getOutputStream();
    PrintWriter out = new PrintWriter(outputStream);
    out.print("GET / HTTP/1.0\r\n\r\n");
    out.flush();
    InputStream inputStream = socket.getInputStream();
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader in = new BufferedReader(inputStreamReader);

    String line;// w  w w . j  a  v a  2  s.c om
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    out.close();
    in.close();
    socket.close();

}

From source file:SecureServer.java

public static void main(String[] args) throws Exception {
    ServerSocketFactory ssf = SSLServerSocketFactory.getDefault();
    SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(98999);
    Socket sock = ss.accept();//from  w w w  .  j av a 2s . c  o m
    ss.close();
    OutputStream rawOut = sock.getOutputStream();
    PrintWriter out = new PrintWriter(new OutputStreamWriter(rawOut));
    out.println(new java.util.Date().toString());
    out.flush();
    sock.close();

}

From source file:Main.java

public static void main(String[] args) {
    char[] c = { 'a', 'b', 'c', 'd' };

    PrintWriter pw = new PrintWriter(System.out);

    // print char array
    pw.print(c);/*  w  w w  .j  a v  a2  s  . c om*/

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'a';

    PrintWriter pw = new PrintWriter(System.out);

    // write char
    pw.write(c);//from  w  w w.java 2 s  .  co  m
    pw.write('b');

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    int i = 123;/*  w w w .  jav  a 2s  . c o  m*/

    PrintWriter pw = new PrintWriter(System.out);

    // print int
    pw.println(i);
    pw.println(987);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'a';

    PrintWriter pw = new PrintWriter(System.out);

    // print string
    pw.println(c);/*from  w  ww.ja v a  2  s .  co m*/
    pw.println('b');

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    float f = 123.456f;

    PrintWriter pw = new PrintWriter(System.out);

    // print float
    pw.println(f);/*  ww w .  jav a2s.c  o  m*/
    pw.println(987.765f);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    PrintWriter pw = new PrintWriter(System.out);

    // print string
    pw.println(s);//from   w w  w . ja  va2  s. co  m
    pw.println("World");

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    char[] c = { 'a', 'b', 'c', 'd', 'e', 'f' };

    PrintWriter pw = new PrintWriter(System.out);

    // write char
    pw.write(c, 1, 3);/*from   w  w  w .  j  av a  2s  .co  m*/
    pw.write(c, 3, 3);

    // flush the writer
    pw.flush();

}