List of utility methods to do FileInputStream Create
InputStream | getStream(String fileName, boolean resource) get Stream if (resource) { return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); return new FileInputStream(fileName); |
InputStream | getStreamForFile(String fileName) Open an input stream from a file, which may exist as a physical file or in a JAR file. File file = new File(fileName); if (file.exists()) { return new FileInputStream(file); } else { return null; |
InputStream | getStreamForFile(String path) get Stream For File String zipFile = ""; for (String segment : path.replace("\\", "/").split("/")) { zipFile += segment + "/"; if (segment.contains(".bin")) break; String file = path.substring(zipFile.length()); return getStreamForFile(zipFile, file); ... |
InputStream | getStreamFromFile(File file) get Stream From File InputStream stream = null; try { if (!file.exists()) { throw new RuntimeException("file " + file + " doesn't exist"); if (file.isDirectory()) { throw new RuntimeException("file " + file + " is a directory"); stream = new FileInputStream(file); } catch (Exception e) { throw new RuntimeException("couldn't access file " + file + ": " + e.getMessage(), e); return stream; |