import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.NumberFormatException;public class StandardInputReader extends BufferedReader { /**
* Constructs a new input stream with the specified standard input stream
*/
public StandardInputReader() {
super(new InputStreamReader(System.in));
} /**
* Read a boolean value from standard input stream.
*
* @return a boolean value.
* @throws IOException
*/
public boolean readBoolean() throws IOException {
String strBoolean = super.readLine(); if (strBoolean.equalsIgnoreCase("true")) {
return true;
} else if (strBoolean.equalsIgnoreCase("false")) {
return false;
} else {
throw new NumberFormatException("For input string: \""
+ strBoolean +"\"");
}
} /**
* Read a byte value from standard input stream.
*
* @return a byte value.
* @throws IOException
*/
public byte readByte() throws IOException {
return Byte.parseByte(super.readLine());
} /**
* Read a short value from standard input stream.
*
* @return a short value.
* @throws IOException
*/
public short readShort() throws IOException {
return Short.parseShort(super.readLine());
} /**
* Read a int value from standard input stream.
*
* @return a int value.
* @throws IOException
*/
public int readInt() throws IOException {
return Integer.parseInt(super.readLine());
} /**
* Read a long value from standard input stream.
*
* @return a long value.
* @throws IOException
*/
public long readLong() throws IOException {
return Long.parseLong(super.readLine());
} /**
* Read a float value from standard input stream.
*
* @return a float value.
* @throws IOException
*/
public float readFloat() throws IOException {
return Float.parseFloat(super.readLine());
} /**
* Read a double value from standard input stream.
*
* @return a double value.
* @throws IOException
*/
public double readDouble() throws IOException {
return Double.parseDouble(super.readLine());
}
}
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.NumberFormatException;public class StandardInputReader extends BufferedReader { /**
* Constructs a new input stream with the specified standard input stream
*/
public StandardInputReader() {
super(new InputStreamReader(System.in));
} /**
* Read a boolean value from standard input stream.
*
* @return a boolean value.
* @throws IOException
*/
public boolean readBoolean() throws IOException {
String strBoolean = super.readLine(); if (strBoolean.equalsIgnoreCase("true")) {
return true;
} else if (strBoolean.equalsIgnoreCase("false")) {
return false;
} else {
throw new NumberFormatException("For input string: \""
+ strBoolean +"\"");
}
} /**
* Read a byte value from standard input stream.
*
* @return a byte value.
* @throws IOException
*/
public byte readByte() throws IOException {
return Byte.parseByte(super.readLine());
} /**
* Read a short value from standard input stream.
*
* @return a short value.
* @throws IOException
*/
public short readShort() throws IOException {
return Short.parseShort(super.readLine());
} /**
* Read a int value from standard input stream.
*
* @return a int value.
* @throws IOException
*/
public int readInt() throws IOException {
return Integer.parseInt(super.readLine());
} /**
* Read a long value from standard input stream.
*
* @return a long value.
* @throws IOException
*/
public long readLong() throws IOException {
return Long.parseLong(super.readLine());
} /**
* Read a float value from standard input stream.
*
* @return a float value.
* @throws IOException
*/
public float readFloat() throws IOException {
return Float.parseFloat(super.readLine());
} /**
* Read a double value from standard input stream.
*
* @return a double value.
* @throws IOException
*/
public double readDouble() throws IOException {
return Double.parseDouble(super.readLine());
}
}
里面有相应的例子。很好懂的。
使用时注意设置路径等问题(具体看readme吧,这一点很重要,我用的时候就在这里卡住过)。