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 "";
fun assetFilePathcontext Context asset String String val file = FilecontextfilesDir assettry val inpStream InputStream = contextassetsopenassettry val outStream = FileOutputStreamfile falseval buffer

原文地址: http://www.cveoy.top/t/topic/iRUr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录