Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

android copy file from assets to sd card

I know this has been answered but I have a slightly more elegant way to copy from asset directory to a file on the sdcard. It requires no "for" loop but instead uses File Streams and Channels to do the work.

(Note) If using any type of compressed file, APK, PDF, ... you may want to rename the file extension before inserting into asset and then rename once you copy it to SDcard)

AssetManager am = context.getAssets();
AssetFileDescriptor afd = null;
try {
    afd = am.openFd( "MyFile.dat");

    // Create new file to copy into.
    File file = new
File(Environment.getExternalStorageDirectory() + + "NewFile.dat");

    copyFdToFile(afd.getFileDescriptor(), file);

} catch (IOException e) {

A way to copy a file without having to loop through it.

public static void
copyFdToFile(FileDescriptor src, File dst) throws
IOException {
    FileChannel inChannel = new
    FileChannel outChannel = new
    try {
        inChannel.transferTo(0, inChannel.size(),
    } finally {
        if (inChannel != null)
        if (outChannel != null)

Thanks to JPM's Answer

Categories : Java

Related to : android copy file from assets to sd card
Read random files from assets on Android
I got the answer, thank you greenapps, for trying to help mee... My mistake was on declaration of array... so my new code is this : int[] numrat = new int[12]; it was like this : int[] numrat = null; another mistake was on the getAssets, like greenapps told me getAssets().open( "/fytyra/" + emri +".jpg"); now thanks to him i changed that code to : getAssets().open( "fytyra/" + emri +".

Categories : Android
Livereload with Ember-CLI; only reload changed assets
I believe this is still a work in progress with Ember CLI and is planned for a future release, or is depending on a fix in Broccoli. See What I've done to get around this probably isn't ideal, but I end up using grunt, and use a shell command to run ember build, copy the output to a different directory that is being served by another server (i

Categories : Ember Js
How to create multi scaled image assets for a WP 8.1 Store app
You create original image for 96dpi device, let's say 40x40, then you should provide 56x56 (140%), 72x72 (180%) and so on. If you don't provide the image, the image will be resized and loose its quality. You can provide images for every scale and place them in the same folder, like this: Images/name.scale-100.png Images/name.scale-140.png Images/name.scale-180.png Images/name.scale-240.png The

Categories : Xaml
How do you force all insecure assets (CSS and JS) to their https version on Laravel?
if you have setup the environments, then use this.... {{ html_style('css/modals.css',[], !App::isLocal()) }} though a more elegant solution is self signed certificate locally.

Categories : PHP
Webview load html from assets directory and send data to
One way of doing this is to have JavaScript bridge apis. Let say you have JS method in HTML like this : function setText(message){ // Set message to Text Box } You can Invoke this JS method from native code(Java) like this: myWebView.loadUrl("javascript:setText(" + text + ")");

Categories : Android
Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 Publishing Limited. All rights reserved.