Tim Van Wassenhove

Passionate geek, interested in Technology. Proud father of two

19 Mar 2005

Formatted input

I was in need for formatted input and the decomposition of the input into a stream of tokens so i came up with the following:

Code: java/TokSequence.java.txt And now i am ready for formatted input like this:

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader input = new BufferedReader(new FileReader("file.txt"));

      for (String in = input.readLine()) {
        TokSequence ts = new TokSequence(new StringTokenizer(in));
        int userId = ts.getIn();
        double score = ts.getDouble();
        String name = ts.getString();
        // do stuff with userId, score and name
      }
    } 
    catch (Exception e) {
      System.err.println(e);
      System.exit(1);
    }
  }  
}