class path rules: accessing ressources from java
class path rules:
accessing ressources from java program
getResourcesAsStream("config/config.properties")
return an input stream for reading the specified resource
:
Without using the leading slash, it will look for your file under the same directory of the .class file where it is used.
System.getProperty("path.separator"));
// discovering system properties relevant to the classpath
import java.util.Properties;
//...
// the classpath
System.out.println( System.getProperty( "java.class.path" ) );
// extension directories whose jars are included on the classpath
System.out.println( System.getProperty( "java.ext.dirs" ) );
// low level classpath, includes system jars
System.out.println( System.getProperty( "java.library.path" ) );
// character to separate (not terminate!) entries on the classpath, ; for Windows : for unix.
System.out.println( System.getProperty( "path.separator" ) );
// To discover the default values for these properties, run Wassup either
// as an Applet or standalone (You will get quite different results each way.)
// See http://mindprod.com/applets/wassup.html
System.getProperty("user.home") or System.getProperty("java.home")).
The resource name given to a Class method may have an initial starting "/" that identifies it as an "absolute" name. Resource names that do not start with a "/" are "relative".
http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.html
InputStream in = new FileInputStream("classpath:xyz.properties")