[英]How to add a local file into a maven project?
Hi I'm trying to use the tokenizer in OpenNLP to develop a maven project. 嗨,我正在尝试使用OpenNLP中的令牌生成器来开发maven项目。 It needs to load a local file, but I don't know how to add it into the project so that even when I launched the project in other machine it still works.
它需要加载本地文件,但是我不知道如何将其添加到项目中,因此即使我在其他计算机上启动该项目,它仍然可以工作。 Like below, the project need to load this local file, how should I configure the file to be added into the project?
如下所示,项目需要加载此本地文件,我应如何配置要添加到项目中的文件?
InputStream modelIn;
try {
modelIn = new FileInputStream("E:\\en-token.bin");
// Make sure the "en-token.bin" file is already in your local disk
TokenizerModel model = null;
try {
model = new TokenizerModel(modelIn);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (modelIn != null) {
try {
modelIn.close();
} catch (IOException e) {
}
}
}
Tokenizer tokenizer = new TokenizerME(model);
String tokens[] = tokenizer.tokenize(string);
List<String> tokenResult = Arrays.asList(tokens);
return tokenResult;
} catch (FileNotFoundException ex) {
return null;
}
此类文件应放在src / main / resources文件夹中,该文件夹将打包到jar文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.