Reputation: 4917
How can I read a file deployed as a resource within a EAR or a WAR?
I want to create a new FileInputStream calling the constructor below.
java.io.FileInputStream.FileInputStream(String)
But the file I want to read is located on path "/glm/src/main/resources/excel_templates" inside the WAR file.
Is it possible to create a FileInputStream with a EAR or WAR based filepath?
Upvotes: 1
Views: 7873
Reputation: 15229
Try something like this:
URL url = SomeClassInEar.getClass().getClassLoader().getResource("rootDirInEar/SubDir/fileInEar.whatever");
File file = new File(url.getPath());
FileInputStream fis = new FileInputStream(file);
Upvotes: 3