|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object In
public class In
Simple input from the keyboard or from a file.
Copyright (c) 2005 Hanspeter Moessenboeck, University of Linz
This class is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
This class is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
This class allows reading formatted data either from the keyboard or from a file. It is intended to be used in an introductory programming course when classes, packages and exceptions are unknown at the beginning. To use it, simply copy In.class into the source file directory.
All input comes from the current input file, which is initially the keyboard. Opening a file with open() makes it the new current input file. Closing a file with close() switches back to the previous input file.
When reading from the keyboard, reading blocks until the user has entered a sequence of characters terminated by the return key. All methods read from this input buffer (including the terminating '\r' and '\n') until the buffer is fully consumed. When a method tries to read beyond the end of the buffer, it blocks again waiting for the next buffer.
End of file detection: When reading from the keyboard, eof can be signaled as ctrl-Z at the beginning of a new line. When reading from a file, eof occurs when an attempt is made to read beyond the end of the file. In either case In.done() returns false if the requested data could not be read because of eof.
Field Summary | |
---|---|
static char |
eof
End of file indicator returned by read() or peek() when no more characters can be read. |
Constructor Summary | |
---|---|
In()
|
Method Summary | |
---|---|
static int |
available()
Current available raw characters. |
static void |
close()
Close the current input file. |
static boolean |
done()
Check if the previous operation was successful. |
static void |
open(java.lang.String fn)
Open a text file for reading The text file with the name fn is opened as the new current input file. |
static char |
peek()
Peek at the next character. |
static char |
read()
Read a raw character (byte). |
static boolean |
readBoolean()
Read a boolean value. |
static char |
readChar()
Read a character, but skip white spaces (byte). |
static double |
readDouble()
Read a double value. |
static java.lang.String |
readFile()
Read the whole file. |
static float |
readFloat()
Read a float value. |
static java.lang.String |
readIdentifier()
Read an identifier. |
static int |
readInt()
Read an integer. |
static java.lang.String |
readLine()
Read a line of text. |
static long |
readLong()
Read a long integer. |
static java.lang.String |
readString()
Read a quote-delimited string. |
static java.lang.String |
readWord()
Read a word. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char eof
Constructor Detail |
---|
public In()
Method Detail |
---|
public static char read()
public static int available()
public static char readChar()
public static boolean readBoolean()
public static java.lang.String readIdentifier()
public static java.lang.String readWord()
public static java.lang.String readLine()
public static java.lang.String readFile()
public static java.lang.String readString()
public static int readInt()
public static long readLong()
public static float readFloat()
public static double readDouble()
public static char peek()
public static void open(java.lang.String fn)
public static void close()
public static boolean done()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |