Java Utililty Methods File to InputStream

List of utility methods to do File to InputStream

Description

The list of methods to do File to InputStream are organized into topic(s).

Method

FileInputStreamnewInputStream(File file)
new Input Stream
try {
    return new FileInputStream(file);
} catch (Exception e) {
    e.printStackTrace();
    return null;
InputStreamnewInputStream(File file)
new Input Stream
try {
    return new BufferedInputStream(new FileInputStream(file));
} catch (IOException e) {
    throw new RuntimeException(e);
FileInputStreamopenInputStream(File file)
open Input Stream
FileInputStream stream = new FileInputStream(file);
return stream;
FileInputStreamopenInputStream(File file)
open Input Stream
if (file.exists()) {
    if (file.isDirectory()) {
        throw new IOException("File '" + file + "' exists but is a directory");
    if (file.canRead() == false) {
        throw new IOException("File '" + file + "' cannot be read");
} else {
...
FileInputStreamopenInputStream(File file)
Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).
if (file.exists()) {
    if (file.isDirectory()) {
        throw new IOException("File '" + file + "' exists but is a directory");
    if (file.canRead() == false) {
        throw new IOException("File '" + file + "' cannot be read");
} else {
...
FileInputStreamopenInputStream(File file)
Open InputStream for a file.
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);
...
InputStreamopenInputStream(File file, boolean buffer)
Opens an InputStream on a file for reading.
return openInputStream(file, buffer, BUFFER_SIZE);
FileInputStreamopenInputStream(File file, boolean refuseEmpty)
open Input Stream
if (file != null && file.exists() && refuseEmpty && file.length() == 0)
    throw new IllegalArgumentException("File \"" + file.getAbsolutePath() + "\" is empty!");
return new FileInputStream(file);
FileInputStreamopenInputStream(String filePath)
open Input Stream
return openInputStream(new File(filePath));
FileInputStreamopenInputStream(String infilename)
open Input Stream
FileInputStream fis = null;
try {
    fis = new FileInputStream(infilename);
} catch (IOException ioe) {
    System.out.println(ioe.getMessage());
return fis;