java获取当前路径

两种办法,使用java.net.URL或者 System.getProperty("user.dir")



使用java.net.URL比较复杂,但存在中文问题



    public static String getRealPath(String filename)...{
        String path="";
        Class theClass=TestHelloWorld.class;  
        java.net.URL  u= theClass.getResource(filename);  
        return u.getPath();
       
       
    }

你可能感兴趣的:(java,.net)