Richard
Richard

Reputation: 8935

Java file path not found

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

Upvotes: 3

Views: 5625

Answers (2)

srikanth
srikanth

Reputation: 120

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

Upvotes: 1

Richard
Richard

Reputation: 8935

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());

Upvotes: 0

Related Questions