private void copyDir(String path) {
String[] files;
try {
files = this.getAssets().list(path);
if (files.length == 0) {
copyFile(path);
} else {
String filePath = "mnt/sdcard" + "/" + path;
File file = new File(filePath);
file.mkdirs();
for (int i = 0; i < files.length; i++) {
String[] files2 = this.getAssets().list(path+"/"+files[i]);
if (files2.length == 0) {
copyFile(path + "/" + files[i]);
} else {
copyDir(path + "/" + files[i]);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void copyFile(String path) {
Log.v("file", path);
InputStream in = null;
FileOutputStream out = null;
try {
String filePath = "mnt/sdcard" + "/" + path;
File file = new File(filePath);
if (!file.exists()) {
in = this.getAssets().open(path);
out = new FileOutputStream(file);
int length = -1;
byte[] buf = new byte[1024];
while ((length = in.read(buf)) != -1) {
out.write(buf, 0, length);
}
out.flush();
in.close();
out.close();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}