If you think the Android project alogger listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jug6ernaut.android.utilites;
//www.java2s.comimport android.content.Context;
import android.content.res.AssetManager;
import java.io.*;
/**
* Created with IntelliJ IDEA.
* User: williamwebb
* Date: 6/29/13
* Time: 10:02 PM
*/publicclass Assets {
publicstaticvoid extract(Context context) {
String source = "";
String destination = context.getFilesDir().toString();
newFile(destination).mkdirs();
copyFolder(context.getAssets(),source,destination);
}
privatestaticvoid copyFolder(AssetManager am, String sourceFolder, String destinationFolder) {
// "Name" is the name of your folder!
String[] files = null;
try {
files = am.list(sourceFolder);
} catch (IOException e) {
System.err.println("Failed to list base folder: " + sourceFolder);
e.printStackTrace();
return;
}
// Analyzing all file on assets subfolder
for (String filename : files) {
String sourceFile,destinationFile;
if(sourceFolder.length()==0)sourceFile = filename;
else sourceFile = sourceFolder + "/" + filename;
destinationFile = destinationFolder + "/" + filename;
File destFile = newFile(destinationFile);
if(destFile.exists())continue;
boolean isDir = false;
try{
am.open(sourceFile);
}catch (FileNotFoundException fnfe){
isDir=true;
} catch (IOException e) {
isDir=true;
}
if(isDir){ // is a folder
destFile.mkdirs();
copyFolder(am,sourceFile, destinationFile);
} else { // is a file
InputStream in = null;
OutputStream out = null;
try {
in = am.open(sourceFile);
out = new FileOutputStream(destinationFile);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (IOException e) {
System.err.println("Failed to copy: " + sourceFile);
e.printStackTrace();
}
}
}
}
// Method used by copyAssets() on purpose to copy a file.
privatestaticvoid copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = newbyte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
}