File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Java in General
Bookmark "testing" Watch "testing" New topic


ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
i want to test the stringtokenizer to see if the text between to comma delimeters is there or not ie if i read in this text (hello,how,,,are,you)from a file i want the output to be
could anyone please adjust my code so it will woke please
thanks ben

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(","))
if (rt)
( s2.equals(""));

rt = true;
line = buff.readLine();
if (line == null)
eof = true;
for (Enumeration e = hash.elements();e.hasMoreElements() {
String se = (String)e.nextElement();
}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());

Biju Philip

Joined: Nov 03, 2001
Posts: 7
Hi Ben,
You could do something like the following (you'll likely need to tweak the code to fit your needs). I would recommend trying to keep things simple (no need to use Hashtables, etc.). There are many ways that this can be accomplished - the code below is just an example.
Also, I trust that you will understand the concepts behind the example code below and not just apply the answer directly in what you need to do...
I agree. Here's the link:
subject: testing