android 读取assets指定文件

android 读取assets指定文件_第1张图片

  android 读取assets下指定文件到手机sd卡

    直接上代码(经测试可用)

/**
 * 读取assets/TXUgcSDK.licence 许可证到手机sd卡
 */
private void readAssetsFile() {
    try {
        InputStream in = MyApplication.this.getClass().getClassLoader().getResourceAsStream("assets/TXUgcSDK.licence");
        File file = new File(myContext.getExternalFilesDir(null).getAbsolutePath() + "/TXUgcSDK.licence");
        FileOutputStream fos = new FileOutputStream(file);
        int len = 0;
        byte[] buffer = new byte[1024];
        while ((len = in.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
            fos.flush();
        }
        in.close();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

 

 

 

 

 

你可能感兴趣的:(android)