Reputation: 5121
I'm trying to copy a large number of folders and subfolders from my apk asset folder to my sd card quickly. the folders contain 12mb of small files, probably 2500 total. The code example from this SO question works but it takes over 5 minutes on my device. Is there a faster way to do this?
I originally tried adding the folder to a zip archive and unzipping it after it was moved onto the device but it created to many problems on different devices and was failing a lot throughout the process.
Upvotes: 2
Views: 1375
Reputation: 15746
I've had very good, consistent results with creating a zip file, putting it in raw or assets in my app, and unzipping it when the user first opens the app. I'd recommend you give it another shot, as I've been impressed that I've seen zero issues with hundreds of installs.
The tutorials I based the helper methods to zip and unzip files are here: Unzipping Files w/ Android, and Zipping Files w/ Android
It should be noted that I used the Java API to create the zip that I include with the install of my app. That might be why I had such consistent results unzipping them as well, using the Java API in Android.
Hope this helps! Best of luck!
Upvotes: 1
Reputation: 17140
12mb should save a bit faster that, if you are using the methods from the other SO question, try increasing the buffer size in copyFile
like so,
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[8192]; // 1024 is kind small,..try 8192 or 4096!!
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
Upvotes: 1