InputStream from relative path
Solution 1:
Use FileInputStream
:
InputStream is = new FileInputStream("/res/example.xls");
But never read from raw file input stream as this is terribly slow. Wrap it with buffering decorator first:
new BufferedInputStream(is);
BTW leading slash means that the path is absolute, not relative.
Solution 2:
InputStream inputStream = Files.newInputStream(Path);
Solution 3:
Initialize a variable like: Path filePath
, and then:
FileInputStream fileStream;
try {
fileStream = new FileInputStream(filePath.toFile());
} catch (Exception e) {
throw new RuntimeException(e);
}
Done ! Using Path you can have access to many useful methods.