public final class In extends Object
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 and Description |
|---|
In()
Create an input stream from standard input.
|
In(File file)
Create an input stream from a file.
|
In(Scanner scanner)
Create an input stream from a given Scanner source; use with
new Scanner(String) to read from a string.
|
In(Socket socket)
Create an input stream from a socket.
|
In(String s)
Create an input stream from a filename or web page name.
|
In(URL url)
Create an input stream from a URL.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the input stream.
|
boolean |
exists()
Does the input stream exist?
|
boolean |
hasNextChar()
Is the input empty (including whitespace)? Use this to know
whether the next call to
readChar() will succeed. |
boolean |
hasNextLine()
Does the input have a next line? Use this to know whether the
next call to
readLine() will succeed. |
boolean |
isEmpty()
Is the input empty (except possibly for whitespace)? Use this
to know whether the next call to
readString(),
readDouble(), etc will succeed. |
static void |
main(String[] args)
Test client.
|
String |
readAll()
Read and return the remainder of the input as a string.
|
double[] |
readAllDoubles()
Read all doubles until the end of input is reached, and return them.
|
int[] |
readAllInts()
Read all ints until the end of input is reached, and return them.
|
String[] |
readAllStrings()
Read all strings until the end of input is reached, and return them.
|
boolean |
readBoolean()
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 |
readDouble()
Read and return the next double.
|
static double[] |
readDoubles()
Deprecated.
Clearer to use
StdIn.readAllDoubles() |
static double[] |
readDoubles(String filename)
Deprecated.
Clearer to use
new In(filename).
readAllDoubles() |
float |
readFloat()
Read and return the next float.
|
int |
readInt()
Read and return the next int.
|
static int[] |
readInts()
Deprecated.
Clearer to use
StdIn.readAllInts() |
static int[] |
readInts(String filename)
Deprecated.
Clearer to use
new In(filename).
readAllInts() |
String |
readLine()
Read and return the next line.
|
long |
readLong()
Read and return the next long.
|
short |
readShort()
Read and return the next short.
|
String |
readString()
Read and return the next string.
|
static String[] |
readStrings()
Deprecated.
Clearer to use
StdIn.readAllStrings() |
static String[] |
readStrings(String filename)
Deprecated.
Clearer to use
new In(filename).
readAllStrings() |
public In()
public In(Socket socket)
public In(URL url)
public In(File file)
public In(String s)
public In(Scanner scanner)
Note that this does not create a defensive copy, so the scanner will be mutated as you read on.
public boolean exists()
public boolean isEmpty()
readString(),
readDouble(), etc will succeed.public boolean hasNextLine()
readLine() will succeed. Functionally
equivalent to hasNextChar().
public boolean hasNextChar()
readChar() will succeed. Functionally
equivalent to hasNextLine().
public String readLine()
public char readChar()
public String readAll()
public String readString()
public int readInt()
public double readDouble()
public float readFloat()
public long readLong()
public short readShort()
public byte readByte()
public boolean readBoolean()
public String[] readAllStrings()
public int[] readAllInts()
public double[] readAllDoubles()
public void close()
public static int[] readInts(String filename)
readAllInts()public static double[] readDoubles(String filename)
readAllDoubles()public static String[] readStrings(String filename)
readAllStrings()public static int[] readInts()
StdIn.readAllInts()public static double[] readDoubles()
StdIn.readAllDoubles()public static String[] readStrings()
StdIn.readAllStrings()public static void main(String[] args)
Copyright © 2015. All Rights Reserved.