I google how below code loads the resource
Abc.class.getClassLoader().getResourceAsStream("abc.txt")
and find that it searchs the resource in all jar file and zip file in class path.
But when i tried it I am not able to loads it but if i give package path then I am able to loads it can someone tell me how getResourceAsStream search the class path
Thanks
one scenario is :- My below code is a simple program and my resource file abc.txt is inside com.abc package. when i specify path of package it worked and when i did not it does not work.
package com.abc;
public class ResourceExp {
public static void main(String args[])
{
new ResourceExp().getResource();
}
public void getResource()
{
String name = "abc.txt";
// worked
System.out.println(ResourceExp.class.getClassLoader().getResourceAsStream("com/abc/"+name));
//not workded
//System.out.println(ResourceExp.class.getClassLoader().getResourceAsStream(name));
}
}
if getResourceAsStream looks the resource in all jar file and directory then why i have to specify the package path