Class In

Object
  extended by In

public final class In
extends Object

Input. This class provides methods for reading strings and numbers from standard input, file input, URL, and socket.

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()) and standard output (via System.out.print()). It ensures that standard input works the number formatting used in the textbook.

For additional documentation, see Section 3.1 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.


Constructor Summary
In()
          Create an input stream for standard input.
In(java.io.File file)
          Create an input stream from a file.
In(java.net.Socket socket)
          Create an input stream from a socket.
In(String s)
          Create an input stream from a filename or web page name.
In(java.net.URL url)
          Create an input stream from a URL.
 
Method Summary
 void close()
          Close the input stream.
 boolean exists()
          Does the input stream exist?
 boolean hasNextLine()
          Does the input stream have a next line?
 boolean isEmpty()
          Is the input stream empty?
static void main(String[] args)
          Test client.
 String readAll()
          Read and return the remainder of the input as a string.
 boolean readBoolean()
          Return the next boolean from the input stream, allowing "true" or "1" for true and "false" or "0" for false.
 byte readByte()
          Return the next byte from the input stream.
 char readChar()
          Read and return the next character.
 double readDouble()
          Return the next double from the input stream.
static double[] readDoubles()
          Read doubles from standard input
static double[] readDoubles(String filename)
          Read doubles from file
 double readFloat()
          Return the next float from the input stream.
 int readInt()
          Return the next int from the input stream.
static int[] readInts()
          Read ints from standard input
static int[] readInts(String filename)
          Read ints from file
 String readLine()
          Read and return the next line.
 long readLong()
          Return the next long from the input stream.
 String readString()
          Return the next string from the input stream.
static String[] readStrings()
          Read strings from standard input
static String[] readStrings(String filename)
          Read strings from a file
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

In

public In()
Create an input stream for standard input.


In

public In(java.net.Socket socket)
Create an input stream from a socket.


In

public In(java.net.URL url)
Create an input stream from a URL.


In

public In(java.io.File file)
Create an input stream from a file.


In

public In(String s)
Create an input stream from a filename or web page name.

Method Detail

exists

public boolean exists()
Does the input stream exist?


isEmpty

public boolean isEmpty()
Is the input stream empty?


hasNextLine

public boolean hasNextLine()
Does the input stream have a next line?


readLine

public String readLine()
Read and return the next line.


readChar

public char readChar()
Read and return the next character.


readAll

public String readAll()
Read and return the remainder of the input as a string.


readString

public String readString()
Return the next string from the input stream.


readInt

public int readInt()
Return the next int from the input stream.


readDouble

public double readDouble()
Return the next double from the input stream.


readFloat

public double readFloat()
Return the next float from the input stream.


readLong

public long readLong()
Return the next long from the input stream.


readByte

public byte readByte()
Return the next byte from the input stream.


readBoolean

public boolean readBoolean()
Return the next boolean from the input stream, allowing "true" or "1" for true and "false" or "0" for false.


readInts

public static int[] readInts(String filename)
Read ints from file


readDoubles

public static double[] readDoubles(String filename)
Read doubles from file


readStrings

public static String[] readStrings(String filename)
Read strings from a file


readInts

public static int[] readInts()
Read ints from standard input


readDoubles

public static double[] readDoubles()
Read doubles from standard input


readStrings

public static String[] readStrings()
Read strings from standard input


close

public void close()
Close the input stream.


main

public static void main(String[] args)
Test client.