System.out.println(System.getProperty("user.dir"));
此方法,直接獲取到本工程的絕對路徑
此外,還可以用到如下方法,但效果將不同。
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
這兩人方法,獲取到Bin文件夾,並且對於空格,只有用 表示。
2、如果是插件項目,想要獲取被激活項目的絕對路徑,則用以下方法
List<?> list = ((StructuredSelection)selection).toList();
for (Object obj: list) {
this.obj= obj;
//System.out.println(obj.getClass());
}
IProject project = (IProject) this.obj;
String path= project.getLocation().makeAbsolute().toFile().getAbsolutePath();
先獲取到被激活項目的project的引用,然後,再通過工程引用獲取工程的絕對路徑。