String path=Thread.currentThread().getContextClassLoader().getResource("").toString(); path=path.replace('/', '\\'); // 将/换成\
path=path.replace("file:", ""); //去掉file:
path=path.replace("classes\\", ""); //去掉classes\
path=path.replace("target\\", ""); //去掉target\
path=path.substring(1); //去掉第一个\,如 \D:\JavaWeb...
//文件添加下级目录地址
path+= "WEB-INF"+File.separator +"view" + File.separator +"image";
File file = new File(path);
if (!file.exists()) {
}
String filename = System.currentTimeMillis() + UUID.randomUUID().toString() + ".png";
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path + File.separator +filename));
imageOutput.write(fs, 0, fs.length);
imageOutput.close();