import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class InputFileDeclared {
private FileInputStream in;
public InputFileDeclared(String filename) throws FileNotFoundException {
in = new FileInputStream(filename);
}
public String getWord() throws IOException {
int c;
StringBuffer buf = new StringBuffer();
do {
c = in.read();
if (Character.isSpace((char) c))
return buf.toString();
else
buf.append((char) c);
} while (c != -1);
return buf.toString();
}
public static void main(String[] args) throws java.io.IOException {
InputFileDeclared file = new InputFileDeclared("testing.txt");
System.out.println(file.getWord());
System.out.println(file.getWord());
System.out.println(file.getWord());
}
}
|