Java Class
Jump to navigation
Jump to search
Internal
getResourceAsStream()
If the resource name is not prefixed with "/", then the name of the resource will be prepended with the class package name.
For example, the following code:
package my.own.package; public class Main { public static void main(String[] args) { InputStream is = Main.class.getResourceAsStream("example.txt"); } }
will look for a "my/own/package/example.txt" file in the classpath.
If we want to look for "example.txt", use:
getResourceAsStream("/example.txt");