public String doFormFile(FormFile file, String dir) {
try {
File f = new File(dir);
if (!f.exists()) {
f.mkdir();//如果路径不存在,创建
}
InputStream in = file.getInputStream();
FileOutputStream writer = new FileOutputStream(dir + "/" + file.getFileName());
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
writer.write(buffer, 0, bytesRead);
}
writer.flush();
writer.close();
in.close();
file.destroy();
} catch (Exception e) {
e.printStackTrace();
}
return file.getFileName();
}
try {
File f = new File(dir);
if (!f.exists()) {
f.mkdir();//如果路径不存在,创建
}
InputStream in = file.getInputStream();
FileOutputStream writer = new FileOutputStream(dir + "/" + file.getFileName());
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
writer.write(buffer, 0, bytesRead);
}
writer.flush();
writer.close();
in.close();
file.destroy();
} catch (Exception e) {
e.printStackTrace();
}
return file.getFileName();
}