Friday, January 4, 2013

Get InputStream from a given file path using Java

public InputStream fetchInputStream(String filePath) {
InputStream inputStream = this.getClass().getResourceAsStream(filePath);
if (inputStream == null) {
File file = null;
file = new File(filePath);
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return inputStream;
}

No comments: