Java Utililty Methods FileInputStream Create

List of utility methods to do FileInputStream Create

Description

The list of methods to do FileInputStream Create are organized into topic(s).

Method

InputStreamgetStream(String fileName, boolean resource)
get Stream
if (resource) {
    return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
return new FileInputStream(fileName);
InputStreamgetStreamForFile(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;
InputStreamgetStreamForFile(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);
...
InputStreamgetStreamFromFile(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;