Merge pull request #267 from mslxl/javafx

Fix `Unable to move temp file`, `File::renameTo` is problematic.
This commit is contained in:
huanghongxun
2018-02-06 09:54:08 +08:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -202,8 +202,11 @@ public class FileDownloadTask extends Task {
throw new IOException("Unable to delete existent file " + file);
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))
throw new IOException("Unable to make parent directory " + file);
if (!temp.renameTo(file))
throw new IOException("Unable to move temp file from " + temp + " to " + file);
try {
FileUtils.cutFile(temp, file);
} catch (Exception e) {
throw new IOException("Unable to move temp file from " + temp + " to " + file, e);
}
}
if (downloaded != contentLength)

View File

@@ -236,7 +236,12 @@ public final class FileUtils {
doCopyFile(srcFile, destFile);
}
public static void doCopyFile(File srcFile, File destFile)
public static void cutFile(File srcFile, File destFile) throws IOException {
copyFile(srcFile, destFile);
srcFile.delete();
}
private static void doCopyFile(File srcFile, File destFile)
throws IOException {
Files.copy(srcFile.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
}