首页 > 解决方案 > Scanner.skip() NoSuchElementException

问题描述

从文件中读取,这是名为 next 的方法的内容。它接收一个字符串当前参数并检查文件中该字符串的外观,然后跳过它并返回下一个字符串。

但不幸的是,我一直没有收到这样的元素异常

有什么帮助吗?

代码:

Scanner cleanReader = new Scanner(cleanText);
String next;

while(cleanReader.hasNextLine())
{
    Scanner crChild = new Scanner(cleanReader.nextLine());

    if(current == null)
    {
        next = crChild.next();
        //System.out.println(str);
        return next;
    }
    else
    {
        while(crChild.hasNext())
        {
            cleanReader.skip(current);
            next = crChild.next();
            return next;
        }
    }
}

cleanReader.close();

标签: java

解决方案


推荐阅读