简体   繁体   中英

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. 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文件中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM