|
Basic Methods zio package context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object zio.Input
Provides for text input from files
Simple Examples
// This example reads 10 ints from the keyboard. Ints may be // entered on one or more lines. Ints on the same line must be // separated by spaces. Input ink = new Input(); // input from keyboard int [] ary = new int [10]; for(int i=1; i<=10; i+=1) { ary[i] = ink.findAndReadInt(); } // next example copies a file, line by line from "infile.txt" to // "outfile.txt" using the Output class with the Input class Input in = new Input("infile.txt"); Output out = new Output("outfile.txt"); for(;;) { String line = in.readLine(); if( in.eof() ) break; out.writeString(line); out.writeEndOfLine(); } in.close(); out.close();
Constructor Summary | |
Input()
Creates an input object capable of reading from the keyboard. |
|
Input(java.lang.String fileName)
Creates an input object capable of reading from the named file. |
Method Summary | |
void |
close()
Tells operating system your program is finished reading. |
boolean |
eof()
Returns true if the last attempt to read failed because of the end of the input was discovered during that particular read operation. |
double |
findAndReadDouble()
Reads the next real number. |
int |
findAndReadInt()
Reads the next integer. |
java.lang.String |
findAndReadToken()
Reads the next token. |
char |
readChar()
Reads the next character of input. |
java.lang.String |
readLine()
Reads the next line of input. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Input()
public Input(java.lang.String fileName)
fileName
- the name of the file to be read, can be a path nameMethod Detail |
public final char readChar()
readChar()
.
public final java.lang.String readLine()
public final java.lang.String findAndReadToken()
A token is rather like a word, it is a sequence of nonblank chars that is surrounded by blanks, tabs, or line endings. For example, "hi", "23", and "R2D2". Unlike words, punctuation and numbers are considered part of tokens. So if there really are quotation marks in the input, they will be found in the string returned by this method.
public final int findAndReadInt()
Integer.MIN_VALUE
if no token is found.
Causes an error if token cannot be translated
to int
form.
public final double findAndReadDouble()
Double.NaN
if no token is found.
Causes an error if token cannot be translated to
double
form.
public final boolean eof()
public final void close()
Input
or Output
object.
|
author context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |