小编use*_*541的帖子

从txt文件中读取

我写了一个方法,每次看到一个新单词时都会给一个int调用添加1 total:

public int GetTotal() throws FileNotFoundException{
    int total = 0;
    Scanner s = new Scanner(new BufferedReader(new FileReader("Particles/Names.txt")));
    while(s.hasNext()){
        if(s.hasNext()){
            total++;
        }
    }
    return total;
}
Run Code Online (Sandbox Code Playgroud)

这是写它的正确方法吗?

java

0
推荐指数
1
解决办法
196
查看次数

标签 统计

java ×1