public static void savePicToDisk(InputStream in, String dirPath,
String filePath) {
try {
File dir = new File(dirPath);
if (dir == null || !dir.exists()) {
dir.mkdirs();
}
//文件真实路径
String realPath = dirPath.concat(filePath);
File file = new File(realPath);
if (file == null || !file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len = 0;
while ((len = in.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
将图片写到 硬盘指定目录下
于 2022-01-06 10:37:55 首次发布