How to programmatically move files from internal memory to sdcard in android?
-
How to move files from device's internal memory to external memory in android? Please provide code examples. My code is below private void moveFile(File file, File dir) throws IOException { File newFile = new File(dir, file.getName()); FileChannel outputChannel = null; FileChannel inputChannel = null; try { outputChannel = new FileOutputStream(newFile).getChannel(); inputChannel = new FileInputStream(file).getChannel(); inputChannel.transferTo(0, inputChannel.size(), outputChannel); inputChannel.close(); file.delete(); } finally { if (inputChannel != null) inputChannel.close(); if (outputChannel != null) outputChannel.close(); } }
-
Answer:
Remove the trailing slash from your path. It is not needed since example.png is not a directory. Actually do not hardcode the path to the sd card cause it might differ from device to device. Try Environment.getExternalStorageDirectory() to get the path to sdcard then add any trailing path in the end. Please take a look at the https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory().
user5054103 at Stack Overflow Visit the source
Related Q & A:
- How to convert XML files to PDF files?Best solution by Super User
- How do we move videos on a Sony HD Handycam camcorder to a memory stick?Best solution by Yahoo! Answers
- What's a good internal memory camcorder for around $300?Best solution by Yahoo! Answers
- Can you delete files off a memory card?Best solution by tomshardware.com
- How do I save the files on my SD card to the internal memory of my phone?Best solution by forums.androidcentral.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.