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 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 + ".");
    }/* ww  w . ja  v a 2s  .c o m*/
}

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();//w  ww  .  j  av a 2 s .c  o m
    while ((line = in.readLine()) != null) {
        if (line != null) {
            last = line;
        }
    }
    System.out.println(first + "\n" + last);
    in.close();
}

From source file:BRRead.java

public static void main(String args[]) throws IOException {
    char c;/*from   w  w  w .  j  a va  2  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');
}

From source file:Main.java

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

    String text = "q";
    while (true) {
        System.out.print("Please type a message (Q/q to quit) and press enter:");
        text = br.readLine();/*from  w  w  w .ja v a  2 s . c o  m*/
        if (text.equalsIgnoreCase("q")) {
            System.out.println("We have  decided to exit  the   program");
            break;
        } else {
            System.out.println("We typed: " + text);
        }
    }
}

From source file:Main.java

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

    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);

    // Process lines from file
    String line;//w  ww  .j  a  v a2 s.co  m
    while ((line = br.readLine()) != null) {
        char array[] = line.toCharArray();
        System.out.print(array[0]);
    }
}

From source file:UseTrim.java

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

    System.out.println("Enter 'stop' to quit.");
    System.out.println("Enter letter: ");
    do {
        str = br.readLine();
        str = str.trim();

        if (str.equals("I"))
            System.out.println("I");
        else if (str.equals("M"))
            System.out.println("M");
        else if (str.equals("C"))
            System.out.println("C.");
        else if (str.equals("W"))
            System.out.println("W");
    } while (!str.equals("stop"));
}

From source file:ParseDemo.java

public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str;//www. j ava2  s .c o  m
    int i;
    int sum = 0;

    System.out.println("Enter numbers, 0 to quit.");
    do {
        str = br.readLine();
        try {
            i = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            System.out.println("Invalid format");
            i = 0;
        }
        sum += i;
        System.out.println("Current sum is: " + sum);
    } while (i != 0);
}

From source file:TinyEdit.java

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

    System.out.println("Enter lines of text.");
    System.out.println("Enter 'stop' to quit.");
    for (int i = 0; i < 100; i++) {
        str[i] = br.readLine();/*from w  w w  .j  ava  2s. co m*/
        if (str[i].equals("stop"))
            break;
    }

    System.out.println("\nHere is your file:");

    for (int i = 0; i < 100; i++) {
        if (str[i].equals("stop"))
            break;
        System.out.println(str[i]);
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    // 1. Reading input by lines:
    BufferedReader in = new BufferedReader(new FileReader("IOStreamDemo.java"));
    String s, s2 = new String();
    while ((s = in.readLine()) != null)
        s2 += s + "\n";
    in.close();//ww  w . ja va  2s  .co m

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader in = null;//from  w w w. j a v  a2  s .c o m
    in = new BufferedReader(new FileReader("fileeditor.txt"));
    StreamTokenizer st = new StreamTokenizer(in);
    st.eolIsSignificant(false);
    // remove comment handling
    st.slashSlashComments(false);
    st.slashStarComments(false);

    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        if (st.ttype == StreamTokenizer.TT_NUMBER) {
            // the default is to treat numbers differently than words
            // also the numbers are doubles
            System.out.println((int) st.nval);
        } else {
            System.out.println(st.sval);
        }
    }
}