The Artima Developer Community
Sponsored Link

Java Answers Forum
help with counting the number of lines and tokens

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
jason

Posts: 7
Nickname: bibs
Registered: Nov, 2002

help with counting the number of lines and tokens Posted: Nov 26, 2002 5:01 AM
Reply to this message Reply
Advertisement
hello everyone i am stuck with my code i can read in one line of my code but i want to be able to test if i have reached the end of my line or not and when i have i want to be able to read in the next line
and also just say the first line of the file has 10 tokens so i need to have 10 get methods is there a way in which i can change the amount of get methods to be exact with the amount of tokens
for example ben,dave,jim,lee,simon,cris,claire,lauren,frances,alex
now i want 10 get() methods but if the line has 12 tokens i want the get method to change automatcally to 12 get methods is this possible
my code is below
thanks
jason
import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.StringTokenizer.*;

public class RT2 {


public static void main(String[] args) {
String cT = null;
String lT = null;
try {
boolean eol = false;
Vector v2 = new Vector(100);
Vector v = new Vector(100);
FileReader file = new FileReader("Work.txt");
BufferedReader buff = new BufferedReader(file);
String line = buff.readLine();
StringTokenizer s = null;
boolean eof = false;
while (!eof){
s = new StringTokenizer(line.trim(),",",true);
while (s.hasMoreTokens()) {
cT = s.nextToken();
if (cT.equals(",") && lT.equals(",")){
v.add("");
}
else
if (!cT.equals(",")) {
v.add(cT);
}
lT = cT;

}
//line = buff.readLine();
//if (line == null)
eof = true;
}
for (Enumeration e = v.elements();e.hasMoreElements();) {
String se = (String)e.nextElement();
v2.add(se);
}
String s1 = (String)v2.get(1);
String s2 = (String)v2.get(0);

System.out.println(s1 + "\n" + s2);

buff.close();
}catch (FileNotFoundException fe) {
System.out.println("Error - - " + fe.toString());
}catch (NumberFormatException ne) {
System.out.println("Error - - " + ne.toString());
} catch (IOException e) {
System.out.println("Error - - " + e.toString());

}
}
}

Topic: help with reading in a line from a txt file Previous Topic   Next Topic Topic: Cryptarithms HELP PLEASE!!!!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use