?? gdwebpath.java
字號:
package com.gd.mvc.util;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
/**
* 這是公用類,用來獲取Web環境的路徑,名稱等信息.
*/
public class GdWebPath {
private String webName;
private String webPhysicsPath;
private String systemName;
private String systemPath;
/**
* 該名稱返回的是Web名稱,如:myApp
* @return String
*/
public String getWebName(){
return this.webName;
}
/**
* 該路徑指的是Web環境的物理路徑,如:D:/eclipse/workspace/myApp
* @return String
*/
public String getWebPhysicsPath(){
return this.webPhysicsPath;
}
public void getPath() throws IOException {
Class cls2 = this.getClass();
ProtectionDomain pDomain = cls2.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation();//file:/D:/eclipse/workspace/myApp/WEB-INF/classes/com/gd/web/WebPath.class
webPhysicsPath = loc.toString().substring(loc.toString().indexOf("/") + 1, loc.toString().indexOf("WEB-INF") - 1);
int num = webPhysicsPath.lastIndexOf("/");
webName = webPhysicsPath.substring(num + 1, webPhysicsPath.length());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -