Share on Google+Share on Google+

BufferReader Example

Advertisement
In this tutorial you will see how BufferReader Class is used to read the character at the command line.

Code:

import java.io.*;

class BufferedRead {
public static void main(String args[])
throws IOException {
char c;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nEnter character 'x' to quit");

do {
c = (char) br.read();
} while (c != 'x');

}
}

How to run this example:

c:\yourJavaFileDir>javac BufferedRead.java

c:\yourJavaFileDir>java BufferedRead

Enter character 'x' to quit

Type the text and to quit type x and press enter to exit

The throw keyword example in java
This tutorial will demonstrate the use of the throw keyword. In this example you will see a sub-class is made of Exception. The throw keyword helps to call the subclass of Exception class that you made.
 

Advertisements

Posted on: March 24, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.