networking - What is the best way to transfer bytes between files on network in Java -


the code written in java 1.7

i want make major modifications binary file on slow network.to protect against network connection being lost instead of writing directly file write new file. when have completed writing new file delete old file , rename new file old file.

my question is better new file 1. on same location original file 2. locally on computer

with 1. writing file slower, rename should quicker in fact oses immediate . 2 writing file should quicker renaming filwe slower.

i feel answer 1.

actually if open filechannel both files , transfer files directly 1 channel bytes have come network computer , network or can been copied directly 1 place on network the ther.

i'm guessing here files mounted via network file system (nfs, smb) on computer. can access them local files; slower.

as first question: you're not gaining first writing file locally. in end, have move file correct place in network , involves "copy bytes" operation. example, java's file.rename() fail when 2 files aren't on same harddisk / mount. have manually copy bytes destination folder anyway. io frameworks when necessary happens.

as directly copying data between 2 remote hosts: there few network filesystems support such operations it's special feature. usual culprits (nfs , smb) don't. download whole file source , upload target.


Comments