文件名含有空格导致的路径错误
问题如题,解决办法就是在java后台对含有空格资源文件的路径进行解码,如下:
public static String getProperties(String key, String fileUrl) throws IOException{ Properties properties = new Properties(); URL dataUrl = PropertiesRWUtil.class.getClassLoader().getResource(fileUrl); /*这里要解码一下,防止路径中有空格,浏览器会将空格转为20%,这样系统就找不到文件的指定路径*/ FileInputStream fis = new FileInputStream(URLDecoder.decode(dataUrl.getPath(),"UTF-8")); properties.load(fis); String value = properties.getProperty(key); fis.close(); return value; }