3

I am using Java8 with Spring running on a Wildfly server.

I have the following package:

enter image description here

In LanguageChunkerServiceImpl, I am trying to get a handle on en-parser-chunking.bin, but I get a error:

java.io.FileNotFoundException: en-parser-chunking.bin (The system cannot find the file specified)

My code:

LanguageChunkerServiceImpl.java

new FileInputStream("en-parser-chunking.bin");

or

new FileInputStream("./src/main/java/com/jobs/spring/service/lang/en-parser-chunking.bin");

When I run this from the main method, the following does work though:

new FileInputStream("./src/main/java/com/jobs/spring/service/lang/en-parser-chunking.bin");

Can anyone please advise what the path should be?

Thank you

8
  • stackoverflow.com/questions/4871051/… Find your root path and navigate to it. Commented Nov 15, 2016 at 16:30
  • You probably want to take a look at Class#getResourceAsStream. Commented Nov 15, 2016 at 16:30
  • this can help you Commented Nov 15, 2016 at 16:32
  • Thanks. I tried this, ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader.getResource("en-parser-chunking.bin"); but resource is null Commented Nov 15, 2016 at 16:42
  • I would rather not get the absolute path of the current location, and then deprive the required files location from there. I think this may not work when I deploy to other servers. Commented Nov 15, 2016 at 16:53

2 Answers 2

1

You should put the file in resource folder not in src/java, if your using spring.

Sign up to request clarification or add additional context in comments.

Comments

0

The following works:

If you are using Spring, put the file in the resources dir.

        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource("en-parser-chunking.bin").getFile());
        System.out.println(file.getAbsolutePath());
        modelInParse = new FileInputStream(file.getAbsolutePath());

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.