Last active
September 12, 2017 02:54
-
-
Save imReker/a290ad691a596678c6efd0f9cf2f4e9c to your computer and use it in GitHub Desktop.
[Android] Quick Copy/Extract files in assets to storage with java.nio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Change the file extension of the files in assets that your want to copy to 'jpg'. | |
If you don't want change the extension, you can add | |
aaptOptions { | |
noCompress 'pdf' //Change to the extension of your assets files | |
} | |
to build.gradle. | |
*/ | |
AssetFileDescriptor fd = null; | |
FileChannel outChannel = null; | |
FileChannel inChannel = null; | |
try { | |
fd = getAssets().openFd("AssetsFileName.pdf.jpg"); | |
inChannel = fd.createInputStream().getChannel(); | |
outChannel = new FileOutputStream("Destination.pdf").getChannel(); | |
inChannel.transferTo(fd.getStartOffset(), fd.getLength(), outChannel); | |
} catch (IOException e) { | |
} finally { | |
try { | |
if (outChannel != null) outChannel.close(); | |
if (inChannel != null) inChannel.close(); | |
if (fd != null) fd.close(); | |
} catch (IOException e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment