vendredi 25 mars 2022

Java play framework null pointer exception in reflection giving file

In java play framework project I do not figure out in retrieving file sample.txt in same package of my current controller class.

I try with this command:

URL resource = MyController.class.getResource("text.txt");

This is my current project structure:

- app
---- test
--------- controller
------------- MyController
------------- text.txt

I have tried with a similar command:

 InputStream resource = MyController.class.getResourceAsStream("text.txt");

or

ClassLoader cl = getClass().getClassLoader();
File file = new File(cl.getResource("text.txt").getFile());

Same null pointer.

How can I solve it?





Aucun commentaire:

Enregistrer un commentaire