|
Right, so now I am working on a java project which is essentially useless (Ah, the joys of a first semester module!), it takes in data from a text file and then, using constructors and methods will output them to a pretty invoicing system (Which works fine, took about an hour). Now, the constructors etc. all work fine, but for the life of me I cannot get my String tokenizer to work correctly. It crashes on running (No IOException, my Dummy points both print out, so it is to do with the actual Variable assignment section, which is marked by a comment)
I have no idea what I've done wrong, but I hope you uber-leet types can help out! ;)
import java.io.*; import java.util.*;
class Tokenizer { public static void main (String[] args) { Tokenizer tt = new Tokenizer(); tt.dbTest(); }
void dbTest() { DataInputStream dis = null; String dbRecord = null;
try { System.out.println("Dummy Test. Error point 1"); File f = new File("Data.db"); FileInputStream fis = new FileInputStream(f); BufferedInputStream bis = new BufferedInputStream(fis); dis = new DataInputStream(bis);
while ( (dbRecord = dis.readLine()) != null) { System.out.println("Dummy Test. Error point 2"); StringTokenizer st = new StringTokenizer(dbRecord, " "); //I believe the problem lies in this section. String one = st.nextToken(); String two = st.nextToken(); String three = st.nextToken(); String four = st.nextToken();
System.out.println("1:" + one); System.out.println("2:" + two); System.out.println("3:" + three); System.out.println("4:" + four + "\n"); }
}
catch (IOException e)
{ System.out.println("Uh oh, got an IOException error: " + e.getMessage()); }
finally { if (dis != null) { try { dis.close(); } catch (IOException ioe) { System.out.println("IOException error trying to close the file"); }
}
}
}
}
When twilight dims the skies above Recalling thrills of our love There's one thing I'm certain of Return... I will... to old... BRAZIL.
|