How to move/rename file from internal app storage to external storage on Android?

后端 未结 8 1175
闹比i
闹比i 2020-11-29 02:21

I am downloading files from the internet and saving the streaming data to a temp file in my app\'s internal storage given by getFilesDir().

Once the download is comp

8条回答
  •  爱一瞬间的悲伤
    2020-11-29 02:51

    To copy files from internal memory to SD card and vice-versa using following piece of code:

    public static 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();
        }
    }
    

    And - it works...

提交回复
热议问题