从assset获取文件
因为assets文件夹内文件不能直接获取绝对路径,所以当需要从其中获取特定文件路径的时候,可以将文件copy到能获取路径的地方。
AssetManager am = this.getAssets();
String sdPath = Environment.getExternalStorageDirectory().getPath();
try {
InputStream is = am.open("x5.tbs.apk");
FileOutputStream fos = new FileOutputStream(sdPath + "/x5.tbs.apk");
byte[] buff = new byte[512];
int count = is.read(buff);
while (count != -1) {
fos.write(buff);
count = is.read(buff);
}
is.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
File file = new File(sdPath + "/x5.tbs.apk");
if (file.exists()) {
Log.i(TAG, "onCreate: fileExists");
} else {
Log.i(TAG, "onCreate: fileNotExists");
}
本文来自博客园,作者:北海南竹,转载请注明原文链接:https://www.cnblogs.com/beihainanzhu/p/16356109.html

浙公网安备 33010602011771号