下文筆者講述使用java代碼擷取一個應用程式運作的真實位置,如下所示:
實作思路:
使用new File(".").getCanonicalPath()方法
即可擷取程式的運作路徑
package com.java265.other;
import java.io.File;
public class Test16 {
/**
* java265.com 示例程式
*
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// 擷取程式運作的真實路徑
String s = new File(".").getCanonicalPath();
System.out.println("運作路徑: " + s);
}
}
------運作以上代碼,将輸出以下資訊----
運作路徑: E:\eclipse-workspace\testCmd