Read an input stream with or without the classloader
Last Updated on Friday, 22 February 2013 09:09
Loading an input stream in Java
If you want to load a resource using a specified name from the search path in your java application you need to take into account the following rules :
If your file is located in a file structure like this :
You can reach it using the following java snippet :
The method getResourceasStream() in ClassLoader use the given String as the name of the resource without applying any absolute/relative transformation (see the methods in Class). The name should not have a leading slash (/).
Or if you don't access it using the class loader you need to use the slash (/) at the beginning of your resource path.
Related articles :
If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on
Tags: java, stream, file, input, resource, classloader, slash