如何将assets下的文本路径放入File类里?

qq_28046949 2018-03-11 04:15:18
下了一个别人的小说阅读器项目,项目是这个http://bbs.csdn.net/topics/392326887/close
我想让他读取assets里的txt,接口是List<File> books,但是放不进去。
private List<File> selectDatas1;
selectDatas1.add(new File("file:///android_asset/shiyan.txt"));
放不进去assets的文件,但是手机本地的可以,比如
selectDatas1.add(new File("/storage/emulated/0/Android/data/com.chaozh.iReaderFree15.store/cache/download/shiyan.txt"));
求解怎么解决
...全文
439 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Android小码家 2018-03-11
  • 打赏
  • 举报
回复
不能直接放进去吗? 思路是这样的 将assert中的文件复制到Sd卡里面 用newFiles 装起来 再传给你的那个框架 ArrayList<File> newFiles = new ArrayList<>(); if (!TextUtils.isEmpty(filtertFileName(current))) { Log.e("得到文档文件:", indent + current); String path = Environment.getExternalStorageDirectory().toString() + "/"+"bookPath"; if ( !basePath.exists()){ basePath.mkdirs(); } newFiles.add(writeToLocal(path+current,am.open(current))); } /** * 将InputStream写入本地文件 * @param destination 写入本地目录 * @param input 输入流 * @throws IOException */ private static File writeToLocal(String destination, InputStream input) throws IOException { int index; byte[] bytes = new byte[1024]; FileOutputStream downloadFile = new FileOutputStream(destination); while ((index = input.read(bytes)) != -1) { downloadFile.write(bytes, 0, index); downloadFile.flush(); } downloadFile.close(); input.close(); return new File(destination); }

80,356

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧