配置文件中的定义
方式一:(推荐,解决中英文乱码)
URL url = Thread.currentThread().getContextClassLoader().getResource(ConfigProperties.getProperty("img.url"));
String path = URLDecoder.decode(url.getPath(), "utf-8");
File[] fs = new File(path).listFiles();
以上对应结果为:
方式二:
String fileUrl = this.getClass().getClassLoader().getResource("hwpass/qq.jpg").getPath();
以上对应结果为:
方式三:
String fileUrl2 = GetResource.class.getClassLoader().getResource("hwpass/qq.jpg").getPath();
以上对应结果为:
方式四:(这种方式获取到的路径不是classpath下的)
File file4 = new File(ConfigProperties.getProperty("hwpass.path"));
File absoluteFile = file4.getAbsoluteFile();
以上对应结果为: