• Another alternative in webapps is the ServletContext#getResource() and its counterpart ServletContext#getResourceAsStream().
  • So in such cases we are not required to provide the path we just use getClass().getClassLoader().getResourceAsStream(“Resource-Name”...
  • getResourceAsStream() method is available in java.lang package. ... By using getResourceAsStream() method is to take the resource //.
  • What is getResourceAsStream in Java? ... getResourceAsStream() method returns an input stream for reading the specified resource.
  • The resource in the jar file must be qualified with same package name as the class you call getResourceAsStream from.
  • What does getResourceAsStream do? The getResourceAsStream method returns an InputStream for the specified resource or null if it does not find the resource.
  • These files are often placed in the resources directory and read by methods such as getResource, classLoader.getResource, and getResourceAsStream().
  • public void init() { InputStream is = getClass().getResourceAsStream("prop11.list"); Properties p = new Properties(); try {. p.load(is)
  • Lifepaths.class 's classloader is system classpath classloader, so getResourceAsStream will search user-defined classpath and Lifepaths.txt is there.
  • Table of Contents
    • 1 How to use getresourceasstream ( ) method in Java?
    • 2 How to pass a file path to getresourceasstream?