4

My goal is to move a file from one directory to another. The source is on a local drive and the destination is on a network drive. It doesn't matter whether I move or I copy then delete source. The file is approx 6GB.

What I've tried:

 // C:\path\to\dir\file.bak
File source = new File(localRoot + backup);
// \\192.168.1.100\path\to\dir\file.bak
File dest = new File(storageRoot + "/" + storagePath + "/" + backup); 
try {
    log("Copying");
    // I've tried copyFile as well.
    FileUtils.copyFileToDirectory(source, dest);
    log("copied");
} catch (Exception e) {
    e.printStackTrace();
}

File source = new File(localRoot + backup);
File dest = new File(storageRoot + "/" + storagePath + "/" + backup);
try {
    log("Copying");
    // I've tried move and creating Paths instead of Files as well.
    Files.copy(source.toPath(), dest.toPath());
    log("copied")
} catch (Exception e) {
    e.printStackTrace();
}

I've tried as well a manual method using Input, OutputStreams and reading bytes.

The results is that a file is created in the destination with the correct filename with 0 bytes, and the source file is rewritten from 6GB to 0 bytes. This happens for all methods I've tried, the only exception is that when I tried move, the source file was deleted rather than rewritten.

All code is in early development, please refrain from commenting on best practices. Thank you, and what am I missing or what else can I try?

Gander7
  • 569
  • 1
  • 6
  • 24

0 Answers0