Java Class

From NovaOrdis Knowledge Base
Revision as of 18:26, 25 February 2017 by Ovidiu (talk | contribs) (Created page with "=Internal= * java =getResourceAsStream()= If the resource name is '''not''' prefixed with "/", then the name of the resource will be prepended with the cl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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");