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 = scanner.next();
} catch (FileNotFoundException e) {
    e.printStackTrace();
    next = e.getLocalizedMessage();
}


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

How can I accomplish this?

1 comment
Comment actions Permalink

Okay so I got it to work finally using the answer provided here. https://stackoverflow.com/questions/18717038/adding-resources-in-intellij-for-java-project

Message was edited by: Osama Rao

0

Please sign in to leave a comment.