StreamTokenizerクラスの初学例について

1409 ワード

import java.io.*;
public class FileAnalyzer
{
	public static void main (String args[])
	{
	   try
		   {
		    System.out.print(" :");
		    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		    String filename=br.readLine();
		    FileInputStream fileIn=new FileInputStream(filename);
		    StreamTokenizer in=new StreamTokenizer(fileIn);
		
		    in.ordinaryChar(46);
	        in.ordinaryChar(34);
		    int wordCount=0,numCount=0,punctionCount=0,count=0;
	        double token;
	        while ((token=in.nextToken())!=StreamTokenizer.TT_EOF)
	        {
	        	count++;     	
	           	if (token==StreamTokenizer.TT_WORD)
	        	   wordCount++;
	        	else if (token==StreamTokenizer.TT_NUMBER)
	        	         numCount++;
	        	     else
	        	         punctionCount++;	
	        }
	        System.out.println(" :"+count);
	        System.out.println(" :"+wordCount);
	        System.out.println(" :"+numCount);
	        System.out.println(" :"+punctionCount++);
	       }
	  catch (IOException e)
		   {
		   	System.out.println(e.getMessage());
		   }   	     
    }
	
	
	
	
}