1 @Test 2 public void test02() throws IOException { 3 String path1 = System.getProperty("user.dir") ; 4 System.out.println("当前工程路径----"+path1); 5 String path2 = Test01.class.getPackage().getName().replaceAll("//.","/"); 6 System.out.println("当前包路径---"+path2); 7 String canonicalPath = new java.io.File( "." ).getCanonicalPath(); 8 System.out.println("canonicalPath---"+canonicalPath); 9 }
控制台输出以下:(ps:这是我本地的项目所在路径)
当前工程路径----D:\remote_medical\02\test
当前包路径---com.qtong.test
canonicalPath---D:\remote_medical\02\test
System类属于java.lang包,system类的构造函数的修饰符是private,因此这个类不能够被实例化,加载的时候调用static代码块。java
System类提供了标准输入输出流,错误输出流,获取外部属性和系统环境的方法,加载类库和文件的方法,快速copy数组的方法;其中out和err的类型是PrintStream.web
1 @Test 2 public void test01() throws IOException { 3 Properties properties = System.getProperties(); 4 String[] split = properties.toString().split(","); 5 int i = 0; 6 for (String string : split) { 7 System.out.println(string); 8 } 9 }
控制台输出以下:
1 java.runtime.name = Java(TM) SE Runtime Environment, 2 sun.boot.library.path = D:\aboutDev\java\jdk1.7\jre\bin, 3 java.vm.version = 24.72- b04, 4 java.vm.vendor = Oracle Corporation, 5 java.vendor.url = http://java.oracle.com/, 6 path.separator = ;, 7 java.vm.name = Java HotSpot(TM) 64- Bit Server VM, 8 file.encoding.pkg = sun.io, 9 user.country = CN, 10 user.script = , 11 sun.java.launcher = SUN_STANDARD, 12 sun.os.patch.level = Service Pack 1, 13 java.vm.specification.name = Java Virtual Machine Specification, 14 user.dir = D:\remote_medical\02\test, 15 java.runtime.version = 1.7.0_72- b14, 16 java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment, 17 java.endorsed.dirs = D:\aboutDev\java\jdk1.7\jre\lib\endorsed, 18 os.arch = amd64, 19 java.io.tmpdir = C:\Users\Duchong\AppData\Local\Temp\, 20 line.separator = , 21 java.vm.specification.vendor = Oracle Corporation, 22 user.variant = , 23 os.name = Windows 7, 24 sun.jnu.encoding = GBK, 25 java.library.path =“太长了,因此在这里就不写了”}
看到了一片很好的文章,是对System.getProperty()方法的介绍,是英文的。戳这里Java.lang.System.getProperty() Method数组
网站在这里 服务器