[How to Use] System.getProperty(“user.dir”)

/**
Get the full path to the current class. Last sentence
*/
package test;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
/**
*
java.version Java runtime environment version
java.vendor Java runtime environment vendor
java.vendor.url Java vendor’s URL
java.vm.specification.version Java virtual machine specification version
java.vm.specification.vendor Java virtual machine specification vendor
java.vm.specification.name Java virtual machine specification name
java.vm.version Java virtual machine implementation version
java.vm.vendor Java virtual machine implementation vendor
java.vm.name Java virtual machine implementation name
java.specification.version Java runtime environment specification version
java.specification.vendor Java runtime environment specification vendor
java.specification.name Java runtime environment specification name
os.name The name of the operating system
os.arch The architecture of the operating system
os.version The version of the operating system
file.separator The file separator (“/” on UNIX systems)
path.separator Path separator (” : ” on UNIX systems)
line.separator line separator (“/n” on UNIX systems)
java.home Java installation directory
java.class.version Java class format version number
java.class.path Java class path
java.library.path List of paths to search for when loading libraries
java.io.tmpdir The default temporary file path
java.compiler The name of the JIT compiler to use
java.ext.dirs Path to one or more extension directories
user.name The name of the user’s account
user.home The user’s home directory
user.dir
*/
public class Test {
public static void main(String[] args) throws MalformedURLException, URISyntaxException {
System.out.println(“java.home : “+System.getProperty(“java.home”));
System.out.println(“java.class.version : “+System.getProperty(“java.class.version”));
System.out.println(“java.class.path : “+System.getProperty(“java.class.path”));
System.out.println(“java.library.path : “+System.getProperty(“java.library.path”));
System.out.println(“java.io.tmpdir : “+System.getProperty(“java.io.tmpdir”));
System.out.println(“java.compiler : “+System.getProperty(“java.compiler”));
System.out.println(“java.ext.dirs : “+System.getProperty(“java.ext.dirs”));
System.out.println(“user.name : “+System.getProperty(“user.name”));
System.out.println(“user.home : “+System.getProperty(“user.home”));
System.out.println(“user.dir : “+System.getProperty(“user.dir”));
System.out.println(“===================”);
System.out.println(“package: “+Test.class.getPackage().getName());
System.out.println(“package: “+Test.class.getPackage().toString());
System.out.println(“=========================”);
String packName = Test.class.getPackage().getName();
/*URL packurl = new URL(packName);
System.out.println(packurl.getPath());*/
URI packuri = new URI(packName);
System.out.println(packuri.getPath());
//System.out.println(packuri.toURL().getPath());
System.out.println(packName.replaceAll(“//.”, “/”));
System.out.println(System.getProperty(“user.dir”)+”/”+(Test.class.getPackage().getName()).replaceAll(“//.”, “/”)+”/”);
}
}

Similar Posts: