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:Main.java

public static void main(String... args) throws IOException {
    String oneLine = processFile((BufferedReader b) -> b.readLine());
    System.out.println(oneLine);//from  ww w. ja v  a2 s  .co  m

    String twoLines = processFile((BufferedReader b) -> b.readLine() + b.readLine());
    System.out.println(twoLines);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    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];//from   ww w .ja  va2 s .  c  om
    }
    System.out.println("The average equals " + sum / values.length);
}

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 av a2 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:Main.java

public static void main(String[] args) throws Exception {
    String first, last = null, line;
    BufferedReader in = new BufferedReader(new FileReader(args[0]));
    first = in.readLine();
    while ((line = in.readLine()) != null) {
        if (line != null) {
            last = line;// w  w w  .ja v a2  s.  co  m
        }
    }
    System.out.println(first + "\n" + last);
    in.close();
}

From source file:FileReaderDemo.java

public static void main(String args[]) throws IOException {
    FileReader fr = new FileReader("FileReaderDemo.java");
    BufferedReader br = new BufferedReader(fr);
    String s;/* ww  w  .j  ava  2  s.com*/

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

    fr.close();
}

From source file:MainClass.java

public static void main(String[] a) {

    FileReader fr;/*from  w ww .  j a  v  a2 s.c  o m*/
    try {
        fr = new FileReader(new File("yourFile.txt"));
        BufferedReader br = new BufferedReader(fr);
        String line = br.readLine();
        while (line != null) {
            System.out.println(line);
            line = br.readLine();
        }
        br.close();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:ReadConsole.java

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

    BufferedReader br = new BufferedReader(isr);

    String s;//from  w w w.  j a  va 2 s . c om
    while ((s = br.readLine()) != null) {
        System.out.println(s.length());
    }
    isr.close();
}

From source file:Main.java

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

    String thisLine = null;// w  w w .j  a v  a  2  s.com

    BufferedReader br = new BufferedReader(new FileReader("c:/test.txt"));
    while ((thisLine = br.readLine()) != null) {
        System.out.println(thisLine);
    }

}

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();/* w ww .  ja  v  a2s  . c  o m*/
    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] ap) {
    String line = null;//w w  w . jav  a2 s. c o  m
    int val = 0;
    try {
        BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
        line = is.readLine();
        val = Integer.parseInt(line);
    } catch (NumberFormatException ex) {
        System.err.println("Not a valid number: " + line);
    } catch (IOException e) {
        System.err.println("Unexpected IO ERROR: " + e);
    }
    System.out.println("I read this number: " + val);
}