I have a file in my resources folder in my project in Eclipse. I need a way in which to load this document into my Java file. Preferable representation would be in an InputStream.
I tried the following based on some searching but it does not seem to be working and I am not sure why (I get null), any help appreciated
InputStream is = getClass().getResourceAsStream("/Project/resources/BlankPDF.pdf");
The string which you pass as an argument to
getResourceAsStreamhas to be either the location relative to the class you callgetResourceAsStreamfrom, or absolute w.r.t. any of your source folders, with a leading/.So if
resourcesis a source folder in your project (marked with a little package-like symbol in Eclipse) thengetClass().getResourceAsStream("/BlankPDF.pdf")should work.Example: Say you have the following folders and packages in your project, source folders being marked with a
*:Then both
MyClass.class.getResourceAsStream("/BlankPDF.pdf")(leading/, absolute) andMyClass.class.getResourceAsStream("../../../BlankPDF.pdf")(no leading/, relative) should get you the file.