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 {
    File file = new File(".");

    if (file.isDirectory()) {
        String[] files = file.list();
        for (int i = 0; i < files.length; i++)
            System.out.println(files[i]);
    } else {/*w ww .  jav a2  s  .  c  om*/
        FileReader fr = new FileReader(file);
        BufferedReader in = new BufferedReader(fr);
        String line;
        while ((line = in.readLine()) != null)
            System.out.println(line);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    Hashtable map = new Hashtable();
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    String line;/* w ww  .  j a v a2s.c om*/
    while ((line = br.readLine()) != null) {
        processLine(line, map);
    }
    Enumeration e = map.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + map.get(key));
    }
}

From source file:WordCount.java

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

    Hashtable map = new Hashtable();
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    String line;//from   w  ww  . j  a v a  2s.c o m
    while ((line = br.readLine()) != null) {
        processLine(line, map);
    }
    Enumeration e = map.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + map.get(key));
    }
}

From source file:InputOutputDemoStandardInputOutput.java

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

    //Write characters to standard output and standard error:
    System.out.println("std output");
    System.err.println("std error");
    //Read characters from standard input (the keyboard):
    System.out.print("Type some characters and press Enter: ");
    BufferedReader bisr = new BufferedReader(new InputStreamReader(System.in));
    String response = bisr.readLine();
    System.out.println("You typed: '" + response + "'");
    //Read a byte from standard input (the keyboard):
    System.out.print("Type one character and press Enter: ");
    byte b = (byte) System.in.read();
    System.out.println("First byte of your input is: " + b);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Socket sock = ssock.accept();
    ssock.close();/*  w  w  w .  j a  v a2s . c  o m*/

    PrintStream pstream = new PrintStream(sock.getOutputStream());
    pstream.print("count? ");
    BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    String line = input.readLine();
    pstream.println("");
    int count = Integer.parseInt(line);
    for (int i = count; i >= 0; i--) {
        pstream.println(i);
    }
    pstream.close();
    sock.close();
}

From source file:POP3Demo.java

public static void main(String[] args) throws Exception {
    int POP3Port = 110;
    Socket client = new Socket("127.0.0.1", POP3Port);
    InputStream is = client.getInputStream();
    BufferedReader sockin = new BufferedReader(new InputStreamReader(is));
    OutputStream os = client.getOutputStream();
    PrintWriter sockout = new PrintWriter(os, true);
    String cmd = "user Smith";
    sockout.println(cmd);/*  w w w  .  ja v a 2s  . c  o m*/
    String reply = sockin.readLine();
    cmd = "pass ";
    sockout.println(cmd + "popPassword");
    reply = sockin.readLine();
    cmd = "stat";
    sockout.println(cmd);
    reply = sockin.readLine();
    if (reply == null)
        return;
    cmd = "retr 1";
    sockout.println(cmd);
    if (cmd.toLowerCase().startsWith("retr") && reply.charAt(0) == '+')
        do {
            reply = sockin.readLine();
            System.out.println("S:" + reply);
            if (reply != null && reply.length() > 0)
                if (reply.charAt(0) == '.')
                    break;
        } while (true);
    cmd = "quit";
    sockout.println(cmd);
    client.close();
}

From source file:AllCapsDemo.java

License:asdf

public static void main(String[] arguments) {
    String sourceName = "asdf";
    try {//from  www.  j a  v  a  2 s . c om
        File source = new File(sourceName);
        File temp = new File("cap" + sourceName + ".tmp");

        FileReader fr = new FileReader(source);
        BufferedReader in = new BufferedReader(fr);

        FileWriter fw = new FileWriter(temp);
        BufferedWriter out = new BufferedWriter(fw);

        boolean eof = false;
        int inChar = 0;
        do {
            inChar = in.read();
            if (inChar != -1) {
                char outChar = Character.toUpperCase((char) inChar);
                out.write(outChar);
            } else
                eof = true;
        } while (!eof);
        in.close();
        out.close();

        boolean deleted = source.delete();
        if (deleted)
            temp.renameTo(source);
    } catch (Exception se) {
        System.out.println("Error - " + se.toString());
    }
}

From source file:BufferedSocketClient.java

  public static void main(String args[]) throws Exception {
  Socket socket1;/*  w w  w .  j av  a  2  s.  co  m*/
  int portNumber = 1777;
  String str = "initialize";

  socket1 = new Socket(InetAddress.getLocalHost(), portNumber);

  BufferedReader br = new BufferedReader(new InputStreamReader(socket1.getInputStream()));

  PrintWriter pw = new PrintWriter(socket1.getOutputStream(), true);

  pw.println(str);

  while ((str = br.readLine()) != null) {
    System.out.println(str);
    pw.println("bye");

    if (str.equals("bye"))
      break;
  }

  br.close();
  pw.close();
  socket1.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(8080);

    while (true) {
        try {// ww w  .jav  a 2  s  .co  m
            Socket s = ss.accept();
            OutputStream out = s.getOutputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

            String line = null;
            while (((line = in.readLine()) != null) && (!("".equals(line)))) {
                System.out.println(line);
            }
            StringBuffer buffer = new StringBuffer();
            buffer.append("<HTML><HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n");
            buffer.append("<BODY>\n<H1>Success!</H1></BODY></HTML>\n");

            String string = buffer.toString();
            byte[] data = string.getBytes();
            out.write("HTTP/1.0 200 OK\n".getBytes());
            out.write(new String("Content-Length: " + data.length + "\n").getBytes());
            out.write("Content-Type: text/html\n\n".getBytes());
            out.write(data);
            out.flush();

            out.close();
            in.close();
            s.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:SecureClient.java

public static void main(String[] args) throws Exception {
    String host = "127.0.0.1";

    SocketFactory sf = SSLSocketFactory.getDefault();
    SSLSocket sock = (SSLSocket) sf.createSocket(host, PORT);
    System.out.println("Server connected");

    InputStream rawIn = sock.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(rawIn));
    System.out.println(in.readLine());
    sock.close();/*from  w  w w  .  j av  a 2  s. c o m*/
}