String path = ClassUtils.getDefaultClassLoader().getResource("classpath:static/QRCode.png").getPath(); File file1 = ResourceUtils.getFile("classpath:static/QRCode.png"); // ClassPathResource classPathResource = new ClassPathResource("classpath:static/QRCode.png"); String basepath= URLDecoder.decode(file1.getPath(),"utf-8");//这样就能解决掉那个空格的问题了。