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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader("in.txt"));
    BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt"));
    int i;/*from  ww w. ja  va  2 s. c om*/
    do {
        i = br.read();
        if (i != -1) {
            if (Character.isLowerCase((char) i))
                bw.write(Character.toUpperCase((char) i));
            else if (Character.isUpperCase((char) i))
                bw.write(Character.toLowerCase((char) i));
            else
                bw.write((char) i);
        }
    } while (i != -1);
    br.close();
    bw.close();
}

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 va 2s .c o m
    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 {
    URL url = new URL("http://localhost:1776");
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;/* www .  jav  a2s.  co  m*/
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    in.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();/*ww w  .ja v  a  2  s. c  o  m*/
    int length = tmp.length();
    char c[] = new char[length];
    tmp.getChars(0, length, c, 0);
    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:Main.java

public static void main(String args[]) throws IOException {
    String data, answer = "";
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter any String : ");
    data = br.readLine();//from   w ww  . ja  v  a 2s .  com
    char[] findupper = data.toCharArray();
    for (int i = 0; i < findupper.length; i++) {
        if (findupper[i] >= 65 && findupper[i] <= 91) // ascii value in between 65
                                                      // and 91 is A to Z
        {
            answer += findupper[i]; // adding only uppercase
        }
    }
    System.out.println("Answer : " + answer);
}

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  www.  j  a  va 2s  .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 {
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    StreamTokenizer st = new StreamTokenizer(br);
    st.eolIsSignificant(true);/*from w  w w. j  a v  a2  s .c o  m*/
    int lines = 1;

    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        switch (st.ttype) {
        case StreamTokenizer.TT_EOL:
            ++lines;
        }
    }
    System.out.println("There are " + lines + " lines");
    fr.close();
}

From source file:Main.java

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

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    BufferedReader br = new BufferedReader(sr);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL myURL = new URL("http://www.google.com");
    BufferedReader so = new BufferedReader(new InputStreamReader(myURL.openStream()));
    while (true) {
        String output = so.readLine();
        if (output != null) {
            System.out.println(output);
        } else {//from  www . ja v  a 2 s .  c o  m
            break;
        }
    }
    so.close();
}