Android 获取assets绝对路径

来源:互联网 发布:r230清零软件图解 编辑:程序博客网 时间:2024/06/06 06:41

搜索了很久,发现普通方式获取不到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();


0 0
原创粉丝点击