之前提到如何把文件放到asset目录下,现在就要把文件从asset文件夹中copy到机台里
public boolean copyApkFromAssets(Context context, String fileName, String path) {
boolean copyIsFinish = false;
// Toast.makeText(installCtools.this,this.getString(R.string.text_error),Toast.LENGTH_LONG).show();
try {
InputStream is = context.getAssets().open(fileName);
int count = is.available();
Log.d("matt-","count " + count);
File file = new File(path);
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
byte[] temp = new byte[1024];
int i = 0;
while ((i = is.read(temp)) > 0) {
fos.write(temp, 0, i);
}
fos.close();
is.close();
copyIsFinish = true;
} catch (IOException e) {
e.printStackTrace();
}
return copyIsFinish;
}