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數組
網站在這裏 服務器