//application.properties中設置:(file.path=static/qrfile/)
//保存到static文件夾下的qrfile目錄
@Value("${file.path}")
private String path;
//文件路徑
String path = System.getProperty("java.class.path");
int firstIndex = path.lastIndexOf(System.getProperty("path.separator")) + 1;
int lastIndex = path.lastIndexOf(File.separator) + 1;
path = path.substring(firstIndex, lastIndex) + this.path+pathId;
path = URLDecoder.decode(path, "utf-8");
//在相應路徑下創建文件,若沒有此目錄或文件自動創建
File outputFile = new File(path+".png");
if (!outputFile.exists()) {
outputFile.createNewFile();
}
//文件寫入
FileOutputStream out = new FileOutputStream(filePath + fileName);
out.write(file);
out.flush();
out.close();