Second Program: Printing File contents
File Name: Certification.txt
SCJP certification adds value to your resume.
The above file Certification.txt contents are read and printed.
import java.io.*;
public class FileTokens
{
public static void main(String args[]) throws IOException
{
FileReader freader = new FileReader("Certification.txt");
StreamTokenizer st = new StreamTokenizer(freader);
while(st.nextToken() != st.TT_EOF) // if the token is not end-of-file marker
{
if(st.ttype == st.TT_WORD) // if the token is word
{
System.out.println(st.sval );
}
}
}
}
Certification.txt file is tokenized and in a for loop each token is read. The value returned by the nextToken() method is implicitly stored in sval and printed at DOS prompt.
Pages: 1 2
can you give example on TT_EOL
sir can you plz tell me,
what does resetSyntax() and wordchars(int i, int j) method do
wordchars() we use in StreamTokenizer and regarding resetSyntax() I did not come across in Java.
resetsyntax() it is a method
This method resets this tokenizer’s syntax table so that all characters are “ordinary.” See the ordinaryChar method for more information on a character being ordinary.
What is resetsyntax()? Have I used anywhere?