Example usage for java.io InputStreamReader InputStreamReader

List of usage examples for java.io InputStreamReader InputStreamReader

Introduction

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

Prototype

public InputStreamReader(InputStream in) 

Source Link

Document

Creates an InputStreamReader that uses the default charset.

Usage

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 ww w  .  j  a  v a  2 s  .  c  o m*/
    while ((s = br.readLine()) != null) {
        System.out.println(s.length());
    }
    isr.close();
}

From source file:ReverseConsoleInput.java

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

    // Read and process lines from console
    String s;//from w  w w .j  a  v  a 2 s  .  co m
    while ((s = br.readLine()) != null) {
        StringBuffer sb = new StringBuffer(s);
        sb.reverse();
        System.out.println(sb);
    }
    isr.close();
}

From source file:Main.java

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

    while (true) {
        System.out.print("Radius? ");
        String str = br.readLine();
        double radius;
        try {/* w ww .j av  a2  s. c  o  m*/
            radius = Double.valueOf(str).doubleValue();
        } catch (NumberFormatException nfe) {
            System.out.println("Incorrect format!");
            continue;
        }
        if (radius <= 0) {
            System.out.println("Radius must be positive!");
            continue;
        }
        System.out.println("radius " + radius);
        return;
    }
}

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();/*  w  w  w  .  j  a v  a2s  .c o  m*/
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter a line:");
    System.out.println(stdin.readLine());
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s;//www .  j  a  v a  2s.co m
    while ((s = in.readLine()) != null && s.length() != 0)
        System.out.println(s);
    // An empty line or Ctrl-Z terminates the program
}

From source file:BRReadLines.java

public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str;/*from   w  w  w .jav a 2  s .  c o  m*/

    System.out.println("Enter lines of text.");
    System.out.println("Enter 'stop' to quit.");
    do {
        str = br.readLine();
        System.out.println(str);
    } while (!str.equals("stop"));
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the char:");
    String str = buff.readLine();
    for (int i = 0; i < str.length(); ++i) {
        char c = str.charAt(i);
        int j = (int) c;
        System.out.println("ASCII OF " + c + " = " + j + ".");
    }//from w  w w. j  a  va 2  s  . c o m
}

From source file:MainClass.java

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

    String nextLine = null;//from www. j av a 2  s .c  o  m
    System.out.println("Type any text and press return. Type 'exit' to quit the program.");
    try {
        while ((nextLine = lineCounter.readLine()).indexOf("exit") == -1) {
            if (nextLine == null)
                break;
            System.out.print(lineCounter.getLineNumber());
            System.out.print(": ");
            System.out.println(nextLine);
        }
    } catch (Exception done) {
        done.printStackTrace();
    }
}

From source file:BRRead.java

public static void main(String args[]) throws IOException {
    char c;//from   w w  w .ja v  a2 s . c om
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter characters, 'q' to quit.");
    do {
        c = (char) br.read();
        System.out.println(c);
    } while (c != 'q');
}