How to add a text file to the project?

I have been trying to add a file to my project. I have placed the file parallel to the src folder.

I am calling the file via this piece of code

String next = "";
File mappingsFile = new File("/mapping.json");
try {
    Scanner scanner = new Scanner(mappingsFile);
    next =;
} catch (FileNotFoundException e) {
    next = e.getLocalizedMessage();

I keep getting the FileNotFoundException, specifically that the specified path cannot be found?

How can I accomplish this?


Okay so I got it to work finally using the answer provided here.

Message was edited by: Osama Rao


For anyone experiencing the same problem. I solved it by using the using the Classloader of the thirdparty class containing the code above and setting it on the current thread. Something like the following:

- resource



InputStream resourceStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("");

Please sign in to leave a comment.