fix:dongyang现场代码
This commit is contained in:
@@ -626,7 +626,8 @@ public class FilesUtil {
|
||||
|
||||
// 5. 创建输入输出流
|
||||
in = new BufferedInputStream(connection.getInputStream());
|
||||
out = new BufferedOutputStream(new FileOutputStream(savePath));
|
||||
int lastIndexOf = fileUrl.lastIndexOf("/");
|
||||
out = new BufferedOutputStream(new FileOutputStream(savePath + File.separator + fileUrl.substring(lastIndexOf + 1)));
|
||||
|
||||
// 6. 缓冲区读写数据
|
||||
byte[] buffer = new byte[4096]; // 4KB缓冲区
|
||||
@@ -680,20 +681,7 @@ public class FilesUtil {
|
||||
* @param savePath 完整的文件保存路径
|
||||
*/
|
||||
private static void createDirectoryIfNotExists(String savePath) {
|
||||
// 1. 创建File对象
|
||||
File file = new File(savePath);
|
||||
// 2. 获取文件所在的目录(去掉文件名部分)
|
||||
File parentDir = file.getParentFile();
|
||||
|
||||
// 3. 如果目录不为空且不存在,则创建(mkdirs会创建多级目录)
|
||||
if (parentDir != null && !parentDir.exists()) {
|
||||
boolean isCreated = parentDir.mkdirs();
|
||||
if (isCreated) {
|
||||
log.info("目录不存在,已自动创建:" + parentDir.getAbsolutePath());
|
||||
} else {
|
||||
log.error("创建目录失败:" + parentDir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
try { Files.createDirectories(Paths.get(savePath)); } catch (IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user