Example usage for java.io BufferedReader BufferedReader

List of usage examples for java.io BufferedReader BufferedReader

Introduction

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

Prototype

public BufferedReader(Reader in) 

Source Link

Document

Creates a buffering character-input stream that uses a default-sized input buffer.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    DatagramSocket udpSocket = new DatagramSocket();
    String msg = null;//w w w.ja v  a 2  s  .  c  om
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter a  message  (Bye  to quit):");
    while ((msg = br.readLine()) != null) {
        if (msg.equalsIgnoreCase("bye")) {
            break;
        }
        DatagramPacket packet = Main.getPacket(msg);
        udpSocket.send(packet);
        udpSocket.receive(packet);
        displayPacketDetails(packet);
        System.out.print("Please enter a  message  (Bye  to quit):");
    }
    udpSocket.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Authenticator.setDefault(new MyAuthenticator());
    URL url = new URL("http://hostname:80/index.html");

    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str;//from  w w w .j  av  a2s .c  om
    while ((str = in.readLine()) != null) {
        System.out.println(str);
    }
    in.close();
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Enter a number.");
    double numberFromConsole;
    try {/*from w  w w .  j  a  v  a  2  s.c o  m*/
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String s = br.readLine();
        DecimalFormat df = new DecimalFormat();
        Number n = df.parse(s);
        numberFromConsole = n.doubleValue();
    } catch (IOException e) {
        numberFromConsole = 0;
    } catch (ParseException e) {
        numberFromConsole = 0;
    }
    System.out.println(numberFromConsole);
}

From source file:ReadZip.java

public static void main(String args[]) {
    try {/*  ww w  .j  a v a2 s .  c o  m*/
        ZipFile zf = new ZipFile("ReadZip.zip");
        Enumeration entries = zf.entries();

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        while (entries.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) entries.nextElement();
            System.out.println("Read " + ze.getName() + "?");
            String inputLine = input.readLine();
            if (inputLine.equalsIgnoreCase("yes")) {
                long size = ze.getSize();
                if (size > 0) {
                    System.out.println("Length is " + size);
                    BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
                    String line;
                    while ((line = br.readLine()) != null) {
                        System.out.println(line);
                    }
                    br.close();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

    Process process = new ProcessBuilder(args).start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;/*from w  w w. j  ava2s .  c  o  m*/

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }

}

From source file:DateFormatFile.java

public static void main(String[] args) throws IOException {
    DateFormatFile df = new DateFormatFile();
    BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
    String line;//from   w w  w.  jav  a 2  s .c om
    while ((line = is.readLine()) != null) {
        df.process(line);
    }
}

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();/*from  www. jav a2 s  .c o  m*/
    System.out.println(br.readLine());
    s.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket socket = new Socket("localhost", 12900);
    System.out.println("Started client  socket at " + socket.getLocalSocketAddress());
    BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    BufferedWriter socketWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));

    String promptMsg = "Please enter a  message  (Bye  to quit):";
    String outMsg = null;/*from ww  w. jav a 2s .  co m*/

    System.out.print(promptMsg);
    while ((outMsg = consoleReader.readLine()) != null) {
        if (outMsg.equalsIgnoreCase("bye")) {
            break;
        }
        // Add a new line to the message to the server,
        // because the server reads one line at a time.
        socketWriter.write(outMsg);
        socketWriter.write("\n");
        socketWriter.flush();

        // Read and display the message from the server
        String inMsg = socketReader.readLine();
        System.out.println("Server: " + inMsg);
        System.out.println(); // Print a blank line
        System.out.print(promptMsg);
    }
    socket.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ServerSocket ss = new ServerSocket(80);
    while (true) {
        Socket s = ss.accept();//w  w w.  j ava 2  s .  c om
        PrintStream out = new PrintStream(s.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String info = null;
        while ((info = in.readLine()) != null) {
            System.out.println("now got " + info);
            if (info.equals(""))
                break;
        }
        out.println("HTTP/1.0 200 OK");
        out.println("MIME_version:1.0");
        out.println("Content_Type:text/html");
        String c = "<html> <head></head><body> <h1> hi</h1></Body></html>";
        out.println("Content_Length:" + c.length());
        out.println("");
        out.println(c);
        out.close();
        s.close();
        in.close();
    }
}

From source file:Main.java

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

    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(args);
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;//w ww  . ja v  a  2  s  . c  o m

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }

}