fun assetFilePathcontext Context asset String String val file = FilecontextfilesDir assettry val inpStream InputStream = contextassetsopenassettry val outStream = FileOutputStreamfile falseval buffer
public static String assetFilePath(Context context, String asset) { File file = new File(context.getFilesDir(), asset);
try {
InputStream inpStream = context.getAssets().open(asset);
try {
FileOutputStream outStream = new FileOutputStream(file, false);
byte[] buffer = new byte[4 * 1024];
int read;
while (true) {
read = inpStream.read(buffer);
if (read == -1) {
break;
}
outStream.write(buffer, 0, read);
}
outStream.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
return file.getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
return "";
原文地址: http://www.cveoy.top/t/topic/iRUr 著作权归作者所有。请勿转载和采集!