public static void main(String[] args){
System.out.println("Java運行時環境版本:\n"+System.getProperty("java.version"));
System.out.println("Java 運行時環境供應商:\n"+System.getProperty("java.vendor"));
System.out.println("Java 供應商的URL:\n"+System.getProperty("java.vendor.url"));
System.out.println("Java安裝目錄:\n"+System.getProperty("java.home"));
System.out.println("Java 虛擬機規范版本:\n"+System.getProperty("java.vm.specification.version"));
System.out.println("Java 類格式版本號:\n"+System.getProperty("java.class.version"));
System.out.println("Java類路徑:\n"+System.getProperty("java.class.path"));
System.out.println("加載庫時搜索的路徑列表:\n"+System.getProperty("java.library.path"));
System.out.println("默認的臨時文件路徑:\n"+System.getProperty("java.io.tmpdir"));
System.out.println("要使用的 JIT 編譯器的名稱:\n"+System.getProperty("java.compiler"));
System.out.println("一個或多個擴展目錄的路徑:\n"+System.getProperty("java.ext.dirs"));
System.out.println("操作系統的名稱:\n"+System.getProperty("os.name"));
System.out.println("操作系統的架構:\n"+System.getProperty("os.arch"));
System.out.println("操作系統的版本:\n"+System.getProperty("os.version"));
System.out.println("文件分隔符(在 UNIX 系統中是“/”):\n"+System.getProperty("file.separator"));
System.out.println("路徑分隔符(在 UNIX 系統中是“:”):\n"+System.getProperty("path.separator"));
System.out.println("行分隔符(在 UNIX 系統中是“/n”):\n"+System.getProperty("line.separator"));
System.out.println("用戶的賬戶名稱:\n"+System.getProperty("user.name"));
System.out.println("用戶的主目錄:\n"+System.getProperty("user.home"));
在寫java程序時不可避免要獲取文件的路徑...總結一下,遺漏的隨時補上
1.可以在servlet的init方法里
String path = getServletContext().getRealPath("/");
這將獲取web項目的全路徑
例如 :E:\eclipseM9\workspace\tree\
tree是我web項目的根目錄
2.你也可以隨時在任意的class里調用
this.getClass().getClassLoader().getResource("/").getPath();
這將獲取 到classes目錄的全路徑
例如 : E:\eclipseM9/workspace/tree/WEB-INF/classes/
這個方法也可以不在web環境里確定路徑,比較好用
3.request.getContextPath();
獲得web根的上下文環境
如 /tree
tree是我的web項目的root context
/*jsp 取得當前目錄的路徑
path=request.getRealPath("");
/*得到jbossWEB發布臨時目錄 warUrl=.../tmp/deploy/tmp14544test-exp.war/
path=C:\jboss-4.0.5.GA\server\default\tmp\deploy\tmp14544test-exp.war\
String path = (String)request.getContextPath();
/*得到項目(test)應用所在的真實的路徑 path=/test
String path = request.getRequestURI();
/*得到應用所在的真實的路徑 path=/test/admin/admindex.jsp
String savePath=request.getRealPath(request.getServletPath());
/*得到當前文件的磁盤絕對路徑
//JAVA 取得當前目錄的路徑
File file=new File(".");
String path=file.getAbsolutePath();
path=file.getPath();
/*得到jboss運行目錄 path=C:\jboss-4.0.5.GA\bin\