Java FileInputStream Create getStreamForFile(String fileName)

Here you can find the source of getStreamForFile(String fileName)

Description

Open an input stream from a file, which may exist as a physical file or in a JAR file.

License

Open Source License

Declaration

public static InputStream getStreamForFile(String fileName)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**/*  w ww  .  j  a v a  2 s  . c  o  m*/
     * Open an input stream from a file, which may exist as a physical file or
     * in a JAR file. The name must be valid for both options.
     * 
     * @author Erik Vos
     */
    public static InputStream getStreamForFile(String fileName)
            throws IOException {

        File file = new File(fileName);
        if (file.exists()) {
            return new FileInputStream(file);
        } else {
            return null;
        }
    }
}

Related

  1. getStream(String fileName, boolean resource)
  2. getStreamForFile(String path)
  3. getStreamFromFile(File file)