| | |
Quick TT_EOL question
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 3
Reputation:
Solved Threads: 0
Hello! Can anyone tell me how to make use of the End of Line constant (TT_EOL) when reading data from a file into a Vector? I understand that TT_EOL returns and int, while vectors only hold class types (Double in my case), so how can you compare the two? I would like my program to stop reading tokens into a vector when it reaches the end of the line in a text file. Here is my code, that produces an error stating that I cannot compare a String to an int:
Thanks for any/all help!
Java Syntax (Toggle Plain Text)
public void dataRetrieve(String name) /************************************************************************** *Method Name: dataRetrieve * *Description: This method takes in the name variable and reads the file * line by line, parsing each test name (String) and each test * score (integer). For each line, it adjusts all applicable * variables as necessary and keeps track of total tests and * total scores by range (for each test). It will throw an IO * exception if there are problems reading from the file. * Reads file until no more lines. * * *Precondition: Text file exists. * *Postcondition: Multiple variable values are updated to reflect all file * input. Total tests are counted. * *Author: Melissa M. Cazalet ***************************************************************************/ { try { BufferedReader inputStream = new BufferedReader(new FileReader(name)); String trash = "No trash yet"; testNames = new Vector<String>(); while ((trash = inputStream.readLine()) !=null) { StringTokenizer st = new StringTokenizer(trash); testNames.addElement(st.nextToken()); lineCount++; Vector<Double> tempScores; while(st.nextToken()!= StreamTokenizer.TT_EOL) { tempScores = new Vector<Double>(); tempScores.addElement(new Double(st.nextToken()); } int index; double sum = 0; for(index = 0; index<tempScores.size(); index++) { sum = sum + tempScores.elementAt(index); } double average = sum/tempScores.size(); testMeans.addElement(average); } inputStream.close(); } catch(IOException e) { System.out.println("Problem reading from file."); }
Thanks for any/all help!
![]() |
Similar Threads
- Reformating/reinstalling windows (Windows NT / 2000 / XP)
- Quick Question: Is J# the same thing as Java? (Java)
- Quick RAM Question - DIMM. (Motherboards, CPUs and RAM)
- Quick HijackThis question (Viruses, Spyware and other Nasties)
- quick sort question (C)
- perl for win98 were do i start (Perl)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
- Help me please (C++)
Other Threads in the Java Forum
- Previous Thread: On Click Event for an array of buttons
- Next Thread: Multiple operations from 2 inputs.
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream





