Copy file (image) from CacheDir to SD Card

后端 未结 2 1347
一个人的身影
一个人的身影 2021-01-27 00:46

I want to be able to either move or copy a file from the internal Cache of an android device and put this into permanent storage on the SD Card. This is what I have so far:

2条回答
  •  悲哀的现实
    2021-01-27 01:03

    /**
     * copy file from source to destination
     *
     * @param src source
     * @param dst destination
     * @throws java.io.IOException in case of any problems
     */
    void copyFile(File src, File dst) throws IOException {
        FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dst).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }
    }
    

提交回复
热议问题