关于文件拷贝:待重写加验证
public void copyFilesFromAssets(Context context, String oldPath, String newPath) {
try {
String[] fileNames = context.getAssets().list(oldPath);
Log.w("SunTest","fileNames is "+fileNames.toString());
if (fileNames.length > 0) {
// directory
File file = new File(newPath);
if (!file.mkdir())
{
Log.d("mkdir","can't make folder");
}
for (String fileName : fileNames) {
Log.w("SunTest","in for "+fileName);
copyFilesFromAssets(context, oldPath + "/" + fileName,
newPath + "/" + fileName);
}
} else {
// file
Log.w("SunTest","oldPath is "+oldPath);
InputStream is = context.getAssets().open(oldPath);
FileOutputStream fos = new FileOutputStream(new File(newPath));
byte[] buffer = new byte[1024];
int byteCount;
while ((byteCount = is.read(buffer)) != -1) {
fos.write(buffer, 0, byteCount);
}
fos.flush();
is.close();
fos.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}