java涓幏寰楀綋鍓嶆枃浠惰礬寰勫縐嶆柟娉?/p>
public String getClassPath(){
String path="";
try {
path=new File(getClass().getClassLoader().getResource("").toURI()).getPath();
}catch (URISyntaxException ex) {}
return path;
}
鍙栫▼搴忚繍琛屾椂鐨勭洰褰曡礬寰勩傚嵆紼嬪簭鍦ㄩ偅閲屽弻鍑?yán)L垨BAT鏂囦歡鎵鍦ㄧ殑璺緞
System.getProperties("user.dir");
絎竴縐嶏細(xì)
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
緇撴灉:
C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebin
鑾峰彇褰撳墠綾葷殑鎵鍦ㄥ伐紼嬭礬寰?
濡傛灉涓嶅姞“/”
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
緇撴灉錛?nbsp;
C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebincomtest
鑾峰彇褰撳墠綾葷殑緇濆璺緞錛?/p>
絎簩縐嶏細(xì)
File directory = new File("");//鍙傛暟涓虹┖
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
緇撴灉錛?nbsp;
C:Documents and SettingsAdministratorworkspaceprojectName
鑾峰彇褰撳墠綾葷殑鎵鍦ㄥ伐紼嬭礬寰?
絎笁縐嶏細(xì)
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
緇撴灉錛?nbsp;
file:/C:/Documents%20and%
20Settings/Administrator/workspace/projectName/bin/selected.txt
鑾峰彇褰撳墠宸ョ▼src鐩綍涓媠elected.txt鏂囦歡鐨勮礬寰?/p>
絎洓縐嶏細(xì)
System.out.println(System.getProperty("user.dir"));
緇撴灉錛?nbsp;
C:Documents and SettingsAdministratorworkspaceprojectName
鑾峰彇褰撳墠宸ョ▼璺緞
絎簲縐嶏細(xì)
System.out.println( System.getProperty("java.class.path"));
緇撴灉錛?nbsp;
C:Documents and SettingsAdministratorworkspaceprojectNamebin
鑾峰彇褰撳墠宸ョ▼璺緞
緇濆璺緞鍜岀浉瀵硅礬寰勶細(xì)
緇濆璺緞灝辨槸浣犵殑涓婚〉涓婄殑鏂囦歡鎴栫洰褰曞湪紜洏涓婄湡姝g殑璺緞錛?URL鍜岀墿鐞嗚礬寰?渚嬪錛欳:xyz
est.txt 浠h〃浜唗est.txt鏂囦歡鐨勭粷瀵硅礬寰勩?a style="color: #006600;">http://www.111cn.net 涔熶唬琛ㄤ簡涓涓猆RL緇濆
璺緞銆傜浉瀵硅礬寰勶細(xì)鐩稿涓庢煇涓熀鍑嗙洰褰曠殑璺緞銆傚寘鍚玏eb鐨勭浉瀵硅礬寰勶紙HTML涓殑鐩稿鐩綍錛?/p>
錛屼緥濡傦細(xì)鍦⊿ervlet涓紝"/"浠h〃Web搴旂敤鐨勮窡鐩綍銆傚拰鐗╃悊璺緞鐨勭浉瀵硅〃紺恒備緥濡傦細(xì)"./" 浠?/p>
琛ㄥ綋鍓嶇洰褰?"../"浠h〃涓婄駭鐩綍銆傝繖縐嶇被浼肩殑琛ㄧず錛屼篃鏄睘浜庣浉瀵硅礬寰勩傚彟澶栧叧浜嶶RI錛?/p>
URL,URN絳夊唴瀹癸紝璇峰弬鑰僐FC鐩稿叧鏂囨。鏍囧噯銆俁FC 2396: Uniform Resource Identifiers
(URI): Generic Syntax
[浠ヤ笂鎽樿嚜錛?span style="font-family: verdana, 'courier new'; line-height: 21px;">http://www.111cn.net/jsp/Java/39141.htm]

]]>