java普通类下设置资源文件相对路径

 URL base = this.getClass().getResource("/"); //先获得本类的所在位置,如/home/popeye/testjava/build/classes/net/
        String path = base.getFile();
        //log.i("--path--"+path);
        
        Properties prop = new Properties();
prop.load(HttpsRequest.class.getResourceAsStream("/resources.properties"));
String url = prop.getProperty("wxPayCodeUrl");
//log.i("--url--"+url);
String file = new File(base.getFile(),url).getCanonicalPath();
//log.i("--file--"+file);

你可能感兴趣的:(JavaSE学习笔记)