hello i need to get the text which is between the to tokens (comma) and put it into a hashtable but what i also want is if there is not any text between two commas in the file i want a blank space to be put into a hashtable so when i print it out it will display all the text and the blank spaces
thanks
ben
import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.StringTokenizer.*;
public class ReadSource {
public static void main(String[] args) {
try {
boolean rt = false;
int ic = 1;
String Scounter = new String();
int icounter = 1;
Hashtable hash = new Hashtable(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,",",true);
while (s.hasMoreTokens()) {
String s2 = s.nextToken();
Scounter = String.valueOf(icounter);
if (s2.equals(","))
hash.put(Scounter,s2);
if (rt)
( s2.equals(""));
else
rt = true;
//hash.put(Scounter,s2);
icounter++;
}
line = buff.readLine();
if (line == null)
eof = true;
}
for (Enumeration e = hash.elements();e.hasMoreElements()
{
String se = (String)e.nextElement();
System.out.println(se);
}
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());
}
}
}