赞
踩
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();
- }
- }

赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。