I backup the database normally and saved to a folder using getRuntime (). exec (). I use a very simple method to copy this file using FileChannel.
But it turns out the copy is 0 bytes long. It copies the file before it is complete.
Any tips on how to avoid this?
Putting Loops I do not think it would be trivial, I do not know.
Here is the 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();
}
}