app/src/main/java/org/andstatus/app/util/FileUtils.java
/**
     * Based on <a href="http://www.screaming-penguin.com/node/7749">Backing
     * up your Android SQLite database to the SD card</a>
     *
     * @param src
     * @param dst
     * @return true if success
     * @throws IOException
     */
Based on Backing
up your Android SQLite database to the SD card

@param src
@param dst
@return true if success
@throws IOException
Based on Backing up your Android SQLite database to the SD card @param src @param dst @return true if success @throws IOException
public static boolean copyFile(Object objTag, File src, File dst) throws IOException {
        long sizeIn = -1;
        long sizeCopied = 0;
        boolean ok = false;
        if (src != null && src.exists()) {
            sizeIn = src.length();
            if (!dst.createNewFile()) {
                MyLog.w(objTag, "New file was not created: '" + dst.getCanonicalPath() + "'");
            } else if (src.getCanonicalPath().compareTo(dst.getCanonicalPath()) == 0) {
                MyLog.i(objTag, "Cannot copy to itself: '" + src.getCanonicalPath() + "'");
            } else {
                try (
                        FileInputStream fileInputStream = new FileInputStream(src);
                        java.nio.channels.FileChannel inChannel = fileInputStream.getChannel();
                        FileOutputStream fileOutputStream = newFileOutputStreamWithRetry(dst);
                        java.nio.channels.FileChannel outChannel = fileOutputStream.getChannel();
                ) {
                    sizeCopied = inChannel.transferTo(0, inChannel.size(), outChannel);
                    ok = (sizeIn == sizeCopied);
                }
                dst.setLastModified(src.lastModified());
            }
        }
        MyLog.d(objTag, "Copied " + sizeCopied + " bytes of " + sizeIn);
        return ok;
    }
public static boolean copyFile ( Object objTag , File src , File dst ) throws IOException { long sizeIn = - 1 ; long sizeCopied = 0 ; boolean ok = false ; if ( src != null && src . exists ( ) ) { sizeIn = src . length ( ) ; if ( ! dst . createNewFile ( ) ) { MyLog . w ( objTag , "New file was not created: '" + dst . getCanonicalPath ( ) + "'" ) ; } else if ( src . getCanonicalPath ( ) . compareTo ( dst . getCanonicalPath ( ) ) == 0 ) { MyLog . i ( objTag , "Cannot copy to itself: '" + src . getCanonicalPath ( ) + "'" ) ; } else { try ( FileInputStream fileInputStream = new FileInputStream ( src ) ; java . nio . channels . FileChannel inChannel = fileInputStream . getChannel ( ) ; FileOutputStream fileOutputStream = newFileOutputStreamWithRetry ( dst ) ; java . nio . channels . FileChannel outChannel = fileOutputStream . getChannel ( ) ; ) { sizeCopied = inChannel . transferTo ( 0 , inChannel . size ( ) , outChannel ) ; ok = ( sizeIn == sizeCopied ) ; } dst . setLastModified ( src . lastModified ( ) ) ; } } MyLog . d ( objTag , "Copied " + sizeCopied + " bytes of " + sizeIn ) ; return ok ; }
Based on <a href="http://www.screaming-penguin.com/node/7749">Backing
 up your Android SQLite database to the SD card</a>
Based on <a href = " http : // www . screaming - penguin . com / node / 7749 " > Backing up your Android SQLite database to the SD card< / a >