Java File to InputStream openInputStream(File file)

Here you can find the source of openInputStream(File file)

Description

Open InputStream for a file.

License

Apache License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static FileInputStream openInputStream(File file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    /**/*from  w  w  w .j ava  2 s.  c om*/
     * Open InputStream for a file.
     * @param file
     * @return
     * @throws IOException
     * @since 2012-7-24
     */
    public static FileInputStream openInputStream(File file) throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                throw new IOException("File '" + file + "' exists but is a directory");
            }
            if (!file.canRead()) {
                throw new IOException("File '" + file + "' cannot be read");
            } else {
                return new FileInputStream(file);
            }
        } else {
            throw new FileNotFoundException("File '" + file + "' does not exist");
        }
    }
}

Related

  1. newInputStream(File file)
  2. newInputStream(File file)
  3. openInputStream(File file)
  4. openInputStream(File file)
  5. openInputStream(File file)
  6. openInputStream(File file, boolean buffer)
  7. openInputStream(File file, boolean refuseEmpty)
  8. openInputStream(String filePath)
  9. openInputStream(String infilename)