4
I backup the database normally and save it to a folder using getRuntime(). exec(). I use a very simple method to copy this file using Filechannel.
But it turns out that the copy gets 0 bytes. It copies the file before it is complete.
Any tips on how to avoid this?
Putting loopings I don’t think would be trivial, I don’t know.
Below is code used for copying:
public static void copyFile(File source, File destination) throws IOException {
if (destination.exists())
destination.delete();
FileChannel sourceChannel = null;
FileChannel destinationChannel = null;
try {
sourceChannel = new FileInputStream(source).getChannel();
destinationChannel = new FileOutputStream(destination).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(),
destinationChannel);
} finally {
if (sourceChannel != null && sourceChannel.isOpen())
sourceChannel.close();
if (destinationChannel != null && destinationChannel.isOpen())
destinationChannel.close();
}
}
How are you making these copies? Add the code.
– user28595
Hello Articuno, follow the code in the issue of the question. Thank you.
– Maycon Stanguine
The code worked properly for me. What kind of file is being copied?
– Isac