首页 Easyui社区 easyui学习班 团购 业务 留言版 代码库 归档 登录
2010/1/16 15:12  由 ____′↘夏悸 发表在 · 分类:时光记录生活
· 0 条评论

JAVA得到当前程序的绝对路径的2种方法

Java语言: Codee#8851
01 import java.io.File;  
02  
03 /** 
04 * JAVA得到当前程序的绝对路径 
05 *  
06 * @author JAVA世纪网(java2000.net) 
07 *  
08 */ 
09 public class Test {  
10  
11   public static void main(String[] args) {  
12     System.out.println(getPath());  
13     System.out.println(getPath2());  
14   }  
15  
16   /** 
17    * 通过文件得到当前绝对路径 
18    *  
19    * @return 
20    */ 
21   public static String getPath() {  
22     File f = new File("");  
23     try {  
24       return f.getAbsolutePath();  
25     } finally {  
26       f = null;  
27     }  
28   }  
29  
30   /** 
31    * 从系统变量得到当前绝对路径 
32    *  
33    * @return 
34    */ 
35   public static String getPath2() {  
36     return System.getProperty("user.dir");  
37   }  
38  
39 }