日期:2014-05-20 浏览次数:20729 次
import java.io.*; public class Test1 { 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 st =new StreamTokenizer(fileIn); st.ordinaryChar(46); st.ordinaryChar(34); int wordCount=0,numCount=0,punctionCount=0,count=0; double token; while ((token=st.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()); } } }