下了一个别人的小说阅读器项目,项目是这个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"));
求解怎么解决

解决方案 »

  1.   

    不能直接放进去吗?
    思路是这样的  将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);
        }