Example usage for java.io BufferedReader readLine

List of usage examples for java.io BufferedReader readLine

Introduction

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

Prototype

public String readLine() throws IOException 

Source Link

Document

Reads a line of text.

Usage

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    String fileName = "BigFile.txt";
    FileInputStream fis = new FileInputStream(fileName);
    JLabel filenameLabel = new JLabel(fileName, JLabel.RIGHT);
    Object message[] = { "Reading:", filenameLabel };
    ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis);
    InputStreamReader isr = new InputStreamReader(pmis);
    BufferedReader br = new BufferedReader(isr);
    String line;/*from w ww . j  a v a  2 s.c  o  m*/
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String input = reader.readLine();

    double number = Double.parseDouble(input);

    System.out.println(input + ":" + Math.sqrt(number));

    reader.close();//ww w .  j av  a  2  s  .  c o  m
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String x = in.readLine();
    System.out.println(x);/*from  ww w  . j a  v  a 2  s  .  com*/
    in.close();

}

From source file:MainClass.java

public static void main(String args[]) {
    try {//  w ww .  j a va  2s .com
        System.out.print("Enter your name: ");
        InputStreamReader reader = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(reader);

        String name = in.readLine();
        System.out.println("Hello, " + name + ". Enter three ints...");
        int[] values = new int[3];
        double sum = 0.0;

        for (int i = 0; i < values.length; i++) {
            System.out.print("Number " + (i + 1) + ": ");
            String temp = in.readLine();
            values[i] = Integer.parseInt(temp);
            sum += values[i];
        }

        System.out.println("The average equals " + sum / values.length);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    try {//from   w  w w.ja  v a  2  s.c  o  m
        FileReader fr = new FileReader(args[0]);
        BufferedReader br = new BufferedReader(fr);

        String s;
        while ((s = br.readLine()) != null)
            System.out.println(s);

        fr.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:Sequence.java

public static void main(String args[]) throws IOException {
    Vector v = new Vector(3);
    v.add(new FileInputStream("/etc/motd"));
    v.add(new FileInputStream("foo.bar"));
    v.add(new FileInputStream("/temp/john.txt"));
    Enumeration e = v.elements();
    SequenceInputStream sis = new SequenceInputStream(e);
    InputStreamReader isr = new InputStreamReader(sis);
    BufferedReader br = new BufferedReader(isr);
    String line;/*from w  w  w .  jav a2s. c om*/
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URL u = new URL(args[0]);
    URLConnection uc = u.openConnection();
    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
    String s = br.readLine();
    while (s != null) {
        System.out.println(s);//  w w w .j  a v  a 2 s  .  co  m
        s = br.readLine();
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Vector v = new Vector(3);
    v.add(new FileInputStream("/a/b"));
    v.add(new FileInputStream("yourfile.bar"));
    v.add(new FileInputStream("/yourfile.txt"));

    Enumeration e = v.elements();
    SequenceInputStream sis = new SequenceInputStream(e);
    InputStreamReader isr = new InputStreamReader(sis);
    BufferedReader br = new BufferedReader(isr);
    String line;/* www  . j  av a2  s .  c  om*/
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String tmp = br.readLine();
    int length = tmp.length();
    char c[] = new char[length];
    tmp.getChars(0, length, c, 0);//w ww  .j  av a 2  s  . c  o  m
    CharArrayReader input1 = new CharArrayReader(c);
    int i;
    System.out.print("input1 is:");
    while ((i = input1.read()) != -1) {
        System.out.print((char) i);
    }

}

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  ava 2s  . c  o  m*/
}