Java InputStream Read getInputStreamFile(String URLString)

Here you can find the source of getInputStreamFile(String URLString)

Description

Get the InputStream from a File

License

Open Source License

Parameter

Parameter Description
URLString The URI to the file resource

Exception

Parameter Description
Exception an exception

Return

The InputStream to read the file resource. Close this in calling code.

Declaration

public static InputStream getInputStreamFile(String URLString) throws Exception 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    /**/*from  www  .  ja v  a 2s  .com*/
     * Get the InputStream from a File
     *
     * @param URLString The URI to the file resource
     * @return                  The InputStream to read the file resource. Close this in calling code.
     * @throws Exception
     */
    public static InputStream getInputStreamFile(String URLString) throws Exception {
        final String eLabel = "ResourceRequestUtils.getInputStreamFile: ";
        OutputStream os = null;
        try {
            File file = new File(URLString);
            if ((!file.exists()) || (!file.isFile())) {
                throw new Exception("File resource does not exist: " + URLString);
            }
            return new FileInputStream(file);
        } catch (Exception e) {
            throw new Exception(eLabel + e + " " + URLString);
        } finally {
            try {
                os.close();
            } catch (Exception e) {
            }
        }
    }
}

Related

  1. getInputStream(Class ownerClass, String subName, String extension)
  2. getInputstream(File compressedFile)
  3. getInputStream(JarFile file, ZipEntry entry)
  4. getInputStream(Object caller, String name)
  5. getInputStreamAsResource(Class clazz, String fileName)
  6. getInputStreamFor(String path, Class clazz)
  7. getInputStreamForFileAbsolutePath(String _path)
  8. getInputStreamForResource(String name)
  9. getInputStreamForResource(String relativePath)