一个涉及文件操作读取,以及令牌环的小程序,一直不明白为什么出错,我可是按书上写的阿
从W.TXT中读取数据,然后操作,输出结果,我现在不明白的是为什么在StringTokenizer处报错,说
“StringTokenizer cannot be resolved to a type”,这是什么意思啊
import java.io.*;
import java.text.*;
public class First{
public static void main(String args[])throws IOException,FileNotFoundException{
int a,b,c,d,sum,product;
char str,ch;
StringTokenizer tokenizer;
BufferedReader inFile=new BufferedReader(new FileReader("c:\\w.txt"));
PrintWriter outFile=new PrintWriter(new FileWriter("C:\\q.txt"));
tokenizer=new StringTokenizer(inFile.readLine());
a=Integer.parseInt(tokenizer.nextTokenizer());
b=Integer.parseInt(tokenizer.nextTokenizer());
str=tokenizer.nextToken());
c=Integer.parseInt(tokenizer.nextTokenizer());
d=Integer.parseInt(tokenizer.nextTokenizer());
sum=a+b;
product=c*d;
ch=(char)(str+1);
outFile.print("sum");
outFile.close();
}
}

解决方案 »

  1.   

    java.util 
    Class StringTokenizer
    你没引入前面加import java.util.*;
    str=tokenizer.nextToken()); 把后面的括号去掉。
      

  2.   

    StringTokenizer cannot be resolved to a type
    就是说类型不能识别,找不到类。
      

  3.   

    改了,可是另一个错误又来了
    import java.io.*;
    import java.util.*;
    public class First{
    public static void main(String args[])throws IOException,FileNotFoundException{
    int a,b,c,d,sum,product,num;
    char ch,str;
    StringTokenizer tokenizer;
    BufferedReader inFile=new BufferedReader(new FileReader("c:\\w.txt"));
    PrintWriter outFile=new PrintWriter(new FileWriter("C:\\q.txt"));
    tokenizer=new StringTokenizer(inFile.readLine());
    a=Integer.parseInt(tokenizer.nextToken());
    b=Integer.parseInt(tokenizer.nextToken());
    str=tokenizer.nextToken();
    c=Integer.parseInt(tokenizer.nextToken());
    d=Integer.parseInt(tokenizer.nextToken());
    sum=a+b;
    product=c*d;
    ch=(char)(str+1);
    outFile.print("the sum of "+a+" and "+b+"="+sum +"\n"
          +"the character that comes after "+str+"in the Unicode set is"+ch+"\n"
          +"the product of "+c+" and "+d+"="+product);
    outFile.close();
    }
    }
    现在又有了新的问题,我的w.txt中内容是:
    12 34 
    A
    67 589
     我的问题是怎么样把A的下一个字母算出来,即B,由于str=tokenizer.nextToken();报错,是因为
     字符串不能赋给一个字符,可我又想不到别的方法,转成ASC码也不行,大家帮我啊,该怎么改啊?
      谢谢了