Class In
The Locale used is: language = English, country = US. This is consistent
with the formatting conventions with Java floating-point literals,
command-line arguments (via Double.parseDouble(String)
)
and standard output.
For additional documentation, see Section 3.1 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
Like Scanner
, reading a token also consumes preceding Java
whitespace, reading a full line consumes
the following end-of-line delimeter, while reading a character consumes
nothing extra.
Whitespace is defined in Character.isWhitespace(char)
. Newlines
consist of \n, \r, \r\n, and Unicode hex code points 0x2028, 0x2029, 0x0085;
see
Scanner.java
(NB: Java 6u23 and earlier uses only \r, \r, \r\n).
-
Constructor Summary
ConstructorDescriptionIn()
Create an input stream from standard input.Create an input stream from a file.Create an input stream from a filename or web page name.Create an input stream from a socket.Create an input stream from a URL.Create an input stream from a given Scanner source; use withnew Scanner(String)
to read from a string. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the input stream.boolean
exists()
Does the input stream exist?boolean
Return true if the next value from the input stream can be interpreted as a byteboolean
Is the input empty (including whitespace)? Use this to know whether the next call toreadChar()
will succeed.boolean
Return true if the next value from the input stream can be interpreted as an doubleboolean
Return true if the next value from the input stream can be interpreted as an floatboolean
Return true if the next value from the input stream can be interpreted as an intboolean
Does the input have a next line? Use this to know whether the next call toreadLine()
will succeed.boolean
Return true if the next value from the input stream can be interpreted as a longboolean
isEmpty()
Is the input empty (except possibly for whitespace)? Use this to know whether the next call toreadString()
,readDouble()
, etc will succeed.static void
Test client.readAll()
Read and return the remainder of the input as a string.double[]
Read all doubles until the end of input is reached, and return them.int[]
Read all ints until the end of input is reached, and return them.String[]
Read all strings until the end of input is reached, and return them.boolean
Read and return the next boolean, allowing case-insensitive "true" or "1" for true, and "false" or "0" for false.byte
readByte()
Read and return the next byte.char
readChar()
Read and return the next character.double
Read and return the next double.static double[]
Deprecated.static double[]
readDoubles
(String filename) Deprecated.Clearer to usenew In(filename)
.readAllDoubles()
float
Read and return the next float.int
readInt()
Read and return the next int.static int[]
readInts()
Deprecated.Clearer to useStdIn.readAllInts()
static int[]
Deprecated.Clearer to usenew In(filename)
.readAllInts()
readLine()
Read and return the next line.long
readLong()
Read and return the next long.short
Read and return the next short.Read and return the next string.static String[]
Deprecated.Clearer to useStdIn.readAllStrings()
static String[]
readStrings
(String filename) Deprecated.Clearer to usenew In(filename)
.readAllStrings()
-
Constructor Details
-
In
public In()Create an input stream from standard input. -
In
Create an input stream from a socket. -
In
Create an input stream from a URL. -
In
Create an input stream from a file. -
In
Create an input stream from a filename or web page name. -
In
Create an input stream from a given Scanner source; use withnew Scanner(String)
to read from a string.Note that this does not create a defensive copy, so the scanner will be mutated as you read on.
-
-
Method Details
-
exists
Does the input stream exist? -
isEmpty
Is the input empty (except possibly for whitespace)? Use this to know whether the next call toreadString()
,readDouble()
, etc will succeed. -
hasNextLine
Does the input have a next line? Use this to know whether the next call toreadLine()
will succeed.Functionally equivalent to
hasNextChar()
. -
hasNextChar
Is the input empty (including whitespace)? Use this to know whether the next call toreadChar()
will succeed.Functionally equivalent to
hasNextLine()
. -
readLine
Read and return the next line. -
readChar
Read and return the next character. -
readAll
Read and return the remainder of the input as a string. -
readString
Read and return the next string. -
readInt
Read and return the next int. -
readDouble
Read and return the next double. -
readFloat
Read and return the next float. -
readLong
Read and return the next long. -
readShort
Read and return the next short. -
readByte
Read and return the next byte. -
readBoolean
Read and return the next boolean, allowing case-insensitive "true" or "1" for true, and "false" or "0" for false. -
readAllStrings
Read all strings until the end of input is reached, and return them. -
readAllInts
Read all ints until the end of input is reached, and return them. -
readAllDoubles
Read all doubles until the end of input is reached, and return them. -
close
Close the input stream. -
readInts
Deprecated.Clearer to usenew In(filename)
.readAllInts()
Reads all ints from a file -
readDoubles
Deprecated.Clearer to usenew In(filename)
.readAllDoubles()
Reads all doubles from a file -
readStrings
Deprecated.Clearer to usenew In(filename)
.readAllStrings()
Reads all strings from a file -
readInts
Deprecated.Clearer to useStdIn.readAllInts()
Reads all ints from stdin -
readDoubles
Deprecated.Clearer to useStdIn.readAllDoubles()
Reads all doubles from stdin -
readStrings
Deprecated.Clearer to useStdIn.readAllStrings()
Reads all strings from stdin -
hasNextInt
Return true if the next value from the input stream can be interpreted as an int -
hasNextDouble
Return true if the next value from the input stream can be interpreted as an double -
hasNextFloat
Return true if the next value from the input stream can be interpreted as an float -
hasNextLong
Return true if the next value from the input stream can be interpreted as a long -
hasNextByte
Return true if the next value from the input stream can be interpreted as a byte -
main
Test client.
-
StdIn.readAllDoubles()