Java FileInputStream Read readFileAsInputStream(File file)

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

Description

Read a file as FileInputStream.

License

LGPL

Parameter

Parameter Description
file the file to read

Return

the file as FileInputStream, or null if the file is not found.

Declaration

public static FileInputStream readFileAsInputStream(File file) 

Method Source Code


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

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

public class Main {
    /**// w ww  .ja v  a2s.  c o m
     * Read a file as FileInputStream.
     * 
     * @param fileName
     *            the file name to read
     * @return the file as FileInputStream, or null if the file is not found.
     */
    public static FileInputStream readFileAsInputStream(String fileName) {
        try {
            return new FileInputStream(fileName);
        } catch (FileNotFoundException e) {
            return null;
        }
    }

    /**
     * Read a file as FileInputStream.
     * 
     * @param file
     *            the file to read
     * @return the file as FileInputStream, or null if the file is not found.
     */
    public static FileInputStream readFileAsInputStream(File file) {
        try {
            return new FileInputStream(file);
        } catch (FileNotFoundException e) {
            return null;
        }
    }
}

Related

  1. readFile(String path, String root, OutputStream out)
  2. readFile(String pPathToFile)
  3. readFile(String resource)
  4. readFile(String sFileName)
  5. readFileAsBinary(File file)
  6. readFileAsInputStream(String fileName)
  7. readFileAsProperties(File file)
  8. readFileAsResource(String fileName)
  9. ReadFileAsUtf8String(String filePath)