首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AssertionError:违反: lines.txt存在

AssertionError:违反: lines.txt存在
EN

Stack Overflow用户
提问于 2021-07-16 23:10:06
回答 1查看 161关注 0票数 0

我在lines.txt文件夹下有一个文件Data。问题是,当我将lines.txt作为输入时,我会得到一个错误。错误发生在这一行SimpleReader inFile = new SimpleReader1L(inputFileName);

我知道这与道路有关,因为它没有得到认可,但我没有足够的经验去修复它。有人能告诉我我该怎么做吗?

代码语言:javascript
复制
import components.set.Set;
import components.simplereader.SimpleReader;
import components.simplereader.SimpleReader1L;
import components.simplewriter.SimpleWriter;
import components.simplewriter.SimpleWriter1L;

public final class pp {

public static void main(String[] args) {
        SimpleReader in = new SimpleReader1L();
        SimpleWriter out = new SimpleWriter1L();
        /*
         * Get input file name
         */

        out.print("Input file (with fragments): ");

        String inputFileName = in.nextLine();
        SimpleReader inFile = new SimpleReader1L(inputFileName);

        /*
         * Get initial fragments from input file
         */
        Set<String> fragments = linesFromInput(inFile);
        /*
}
}

我是simpleReader1L

代码语言:javascript
复制
 public SimpleReader1L(String name) {
        assert name != null : "Violation of: name is not null";
        this.name = name;
        try {
            URL url = new URL(name);
            this.rep =
                    new BufferedReader(new InputStreamReader(url.openStream()));
        } catch (MalformedURLException e) {
            // throw new AssertionError("Violation of: " + url + " is valid");
            try {
                this.rep = new BufferedReader(new FileReader(name));
            } catch (FileNotFoundException ex) {
                throw new AssertionError("Violation of: " + name + " exists");
            }
        } catch (FileNotFoundException e) {
            throw new AssertionError("Violation of: " + name + " exists");
        } catch (IOException e) {
            throw new AssertionError("Violation of: " + name + " can be read");
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2021-07-17 01:12:17

错误发生在这一行SimpleReader inFile =newSimpleReader1L(InputFileName);

目前还不清楚SimpleReader1L期望的是什么输入。根据文件对象还是字符串作为fileName,您需要将实际对象或正确的路径作为字符串传递。

使用绝对路径(从根目录开始)。例如:

Windows:D:\somedir\lines.txt

Unix/Mac:/users/<username>/home/lines.txt

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68416103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档