当前位置:   article > 正文

android 读取assets指定文件_获取assets getexternalfilesdir

获取assets getexternalfilesdir

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

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

  1. /**
  2. * 读取assets/TXUgcSDK.licence 许可证到手机sd卡
  3. */
  4. private void readAssetsFile() {
  5. try {
  6. InputStream in = MyApplication.this.getClass().getClassLoader().getResourceAsStream("assets/TXUgcSDK.licence");
  7. File file = new File(myContext.getExternalFilesDir(null).getAbsolutePath() + "/TXUgcSDK.licence");
  8. FileOutputStream fos = new FileOutputStream(file);
  9. int len = 0;
  10. byte[] buffer = new byte[1024];
  11. while ((len = in.read(buffer)) != -1) {
  12. fos.write(buffer, 0, len);
  13. fos.flush();
  14. }
  15. in.close();
  16. fos.close();
  17. } catch (FileNotFoundException e) {
  18. e.printStackTrace();
  19. } catch (IOException e) {
  20. e.printStackTrace();
  21. }
  22. }

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/236018
推荐阅读
相关标签
  

闽ICP备14008679号