java中获得当前文件路径

public  String getClassPath(){
        String path="";
 try {
path=new File(getClass().getClassLoader().getResource("").toURI()).getPath();
     }catch (URISyntaxException ex) {}
        return path;

 

取程序运行时的目录路径。即程序在那里双击或BAT文件所在的路径

System.getProperties("user.dir");

你可能感兴趣的:(java)