搜索了很久,发现普通方式获取不到assets的绝对路径。于是换个思路。。
因为assets绝对路径未知,但是SD卡根目录等目录是已知的。于是可以先将文件转移到已知的目录中,再行操作。
代码如下:
AssetManager am = this.getAssets();
InputStream is = am.open("xxx.apk");
// 获取SD卡根路径
String sdPath = Environment.getExternalStorageDirectory().getPath();
FileOutputStream fos = new FileOutputStream(sdPath + "/xxx.apk");
// 写入SD卡
byte[] buff = new byte[512];
int count = is.read(buff);
while (count != -1){
fos.write(buff);
count = is.read(buff);
}
is.close();
fos.close();