Java InputStream Create getInputStream(String filename)

Here you can find the source of getInputStream(String filename)

Description

Return the contents of a file as InputStream .

License

Open Source License

Parameter

Parameter Description
filename a parameter

Return

stream

Declaration

public static InputStream getInputStream(String filename) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.InputStream;

public class Main {
    /**/*from  ww  w.jav a 2s  .c o  m*/
     * Return the contents of a file as {@link InputStream}.
     *
     * @param filename
     * @return stream
     */
    public static InputStream getInputStream(String filename) {
        // Get the calling class from the stacktrace
        String callerClass = Thread.currentThread().getStackTrace()[2].getClassName();
        try {
            return Class.forName(callerClass).getResourceAsStream(filename);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getInputStream(String content)
  2. getInputStream(String data)
  3. getInputStream(String filename)
  4. getInputStream(String fileName)
  5. getInputStream(String fileName)
  6. getInputStream(String fileName)
  7. getInputStream(String filename)
  8. getInputStream(String filePath)
  9. getInputStream(String fileType, String fileName)