作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 eclipse 中有两个项目用于使用 Apache Open NLP 进行句子解析。一个项目运行良好。但对于其他项目,我遇到了以下错误。
这是我的项目结构,两个项目都有“en-parser-chunking.bin”文件。
OpenNLP 项目运行良好(我从互联网上获得了该项目)。因此,我从那里复制了“en-parser-chunking.bin”文件并将其粘贴到我的图书应用程序项目中。但我遇到了上述错误。我的代码怎么了?有没有其他方法可以将“en-parser-chunking.bin”文件导入到我的图书应用程序项目中?
下面是我在图书应用程序中使用的代码
public void parserAction() throws Exception {
InputStream is = new FileInputStream("en-parser-chunking.bin");
ParserModel model = new ParserModel(is);
Parser parser = ParserFactory.create(model);
Parse topParses[] = ParserTool.parseLine(line, parser, 1);
for (Parse p : topParses){
//p.show();
getNounPhrases(p);
}
}
最佳答案
您应该将其放入属于类路径一部分的目录中。在现代项目中,它位于 /src/main/resources/
下。如果您已将其复制到此位置,则可以获取该文件。
InputStream is =MyClass.class.getResourceAsStream("/en-parser-chunking.bin");
其中MyClass是您的类(class)名称
关于java - "The system cannot find the file specified"en-parser-chunking.bin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44365126/
我是一名优秀的程序员,十分优秀!