Java File to InputStream openInputStream(String path)

Here you can find the source of openInputStream(String path)

Description

Opens an inputStream to the specified file.

License

Open Source License

Parameter

Parameter Description
path a <code>string</code> as the name of the file to load

Return

an inputStream if the file could be found,
or null otherwise

Declaration

public static InputStream openInputStream(String path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2003-2005, 2013 Till Zoppke.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html//from   ww w  .  j  a  v a  2 s .c om
 * 
 * Contributors:
 *     Till Zoppke - initial API and implementation
 ******************************************************************************/

import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**
     * Opens an <code>inputStream</code> to the specified file.
     * 
     * @param path
     *            a <code>string</code> as the name of the file to load
     * @return an <code>inputStream</code> if the file could be found, <br>
     *         or <code>null</code> otherwise
     */
    public static InputStream openInputStream(String path) {
        try {
            return new FileInputStream(path);
        } catch (IOException e) {
            return null;
        }
    }
}

Related

  1. openInputStream(File file)
  2. openInputStream(File file, boolean buffer)
  3. openInputStream(File file, boolean refuseEmpty)
  4. openInputStream(String filePath)
  5. openInputStream(String infilename)
  6. openStream(final Class clazz, final String path)
  7. openStream(final File file)
  8. openStream(InputStream in)