Java File to InputStream openInputStream(File file)

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

Description

open Input Stream

License

Apache License

Declaration

public static FileInputStream openInputStream(File file) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static FileInputStream openInputStream(File file) throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                throw new IOException("File '" + file + "' exists but is a directory");
            }//from   w  w  w.jav a  2s . c om
            if (file.canRead() == false) {
                throw new IOException("File '" + file + "' cannot be read");
            }
        } else {
            throw new FileNotFoundException("File '" + file + "' does not exist");
        }
        return new FileInputStream(file);
    }
}

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)