|
-
StringTokenizer URGENT help please!
Hi everyone, merry christmas! im having a bit of a problem with a string tokenizer! i wondered if someone could show me how its done please.
im trying to set up my own reserved word - END, which will end the program and print a message.
this is what i have so far, i want it to produce a message when it encounters an END and say how many lines it has processed. (i have a text file which is being opened and it looks for the END in there)
import java.io.*;
import java.util.*;
class cw3btest
{
public static void main (String args[])
{
try {
RandomAccessFile inFile = new RandomAccessFile(args[0], "r");
String line; // a string to contain the line read
int nooflines=0;
int i;
while (( line=inFile.readLine() ) != null)
{
System.out.println(line);
nooflines++;
}
System.out.println("[" + nooflines + " lines processed]");
if(line=="END")
{
System.out.println("TPL Finished OK [" + nooflines + " lines processed]");
}
} catch (IOException e)
{
System.out.println("An i/o error has occurred ["+e+"]");
}
}
}
i would be grateful for any help.
Many thanks,
N
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks