|
@@ -34,7 +34,7 @@ public class FileUploader {
|
|
|
boolean isSucDel = file.renameTo(new File(targetFile));
|
|
|
if (!isSucDel) {
|
|
|
// 文件没有成功删除
|
|
|
- ErrReporter.report("文件移动失败:" + file.getCanonicalPath() + " target:" + targetFile);
|
|
|
+ ErrReporter.report("文件移动失败:" + file.getCanonicalPath() + " to:" + targetFile);
|
|
|
}
|
|
|
}
|
|
|
// 移除空的目录
|
|
@@ -60,7 +60,14 @@ public class FileUploader {
|
|
|
} catch (FileNotFoundException fnfe) {
|
|
|
// 有些图片格式,会被系统临时占用,抛出文件被占用异常
|
|
|
Thread.currentThread().sleep(1000);
|
|
|
- in = new FileInputStream(fromFile);
|
|
|
+ // 多线程竞争时,文件流可能是空的,读之前做一次判断,以免处理已经上传过的文件(或已被删除)
|
|
|
+ if (fromFile.exists()) {
|
|
|
+ in = new FileInputStream(fromFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (in == null) {
|
|
|
+ // 多线程竞争时,文件流可能是空的
|
|
|
+ return false;
|
|
|
}
|
|
|
URL urlObj = new URL(uri);
|
|
|
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
|