Reputation: 531
I couldn't find any way to copy some files into asset folder in android. I have to read one file over internet and save it into asset folder in android. All the examples/tutorials talk about copying files from asset folder but none talks about the other way round.
I will appreciate any example for this. Thanks in advance.
Upvotes: 0
Views: 4130
Reputation: 94
You cannot modify assets after installing apk into your device. Why? When you install your app into your device, all the resources including src, assets, libs, res etc. are sort of archived into an APK file. APK file can be thought of as a RAR or ZIP file. Just like you can't modify a RAR after archiving, you can't modify APK.
All you have to do is get a pointer to external storage (SDcard) or internal storage (Downloads folder) and use it to save files you download.
Example:
/*Using external directory*/
String folder = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "youfilename";
OutputStream output = new FileOutputStream(folder + "\" + fileName);
/*whenever you read input from url (inside the while loop)*/
output.write(bytearray, offset, bytecount)
Upvotes: 1
Reputation: 2310
You can't copy files to assets folder after installing the app.You have to copy files you want to use in assets
folder beforehands.There is only one way you can download them External
or Enternal
Storage. If u do not know how to download files.
1) This
Upvotes: 0
Reputation: 1006614
You cannot modify assets -- including adding or removing them -- at runtime. You are welcome to store your downloaded files on internal storage or external storage.
Upvotes: 3