import java.io.* ; import java.util.*; public class MyIo { private BufferedReader fin; private StringTokenizer s; private String b; private boolean moreData; private int charPosition; public MyIo(String fname) throws FileNotFoundException, IOException { fin = new BufferedReader(new FileReader(fname)); moreData = (b = fin.readLine()) != null; if (moreData){ s = new StringTokenizer(b); charPosition = 0; } } public boolean hasMoreData() throws IOException { if (moreData && s.hasMoreTokens()) return true; if (moreData && (b = fin.readLine()) != null){ s = new StringTokenizer(b); charPosition = 0; return hasMoreData();} else { moreData = false; return false;} } public boolean hasMoreChars() throws IOException { return b.length() > charPosition;} public char getNextChar() throws IOException { if (hasMoreChars()) { char ch = b.charAt(charPosition); charPosition++; return ch; } else throw new MyIoException("No more Data while reading char"); } public char getLastChar() throws IOException { if (b.length() >= charPosition) return b.charAt(charPosition-1); else throw new MyIoException("No more Data while re-reading last char"); } public String getNextString() throws IOException { if (hasMoreData()) return s.nextToken(); else throw new MyIoException("No more Data while reading string"); } public int getNextInt() throws IOException { if (hasMoreData()) return Integer.parseInt(s.nextToken()); else throw new MyIoException("No more Data while reading int"); } public double getNextDouble() throws IOException { if (hasMoreData()){ Double d = Double.valueOf(s.nextToken()); return d.doubleValue(); } else throw new MyIoException("No more Data while reading double"); } public String getNextThing() throws IOException { System.out.println(s.countTokens() + " " + s.hasMoreTokens()); if (hasMoreData()){ System.out.println(s.countTokens() + " " + s.hasMoreTokens()); return s.nextToken(); } else throw new MyIoException("No more Data while reading int"); } public void close() throws IOException { fin.close(); } }