美文网首页
遍历assets中的所有文件夹,并把得到的文件放到List集合中

遍历assets中的所有文件夹,并把得到的文件放到List集合中

作者: 糖糖_2c32 | 来源:发表于2019-05-17 11:44 被阅读0次
private List<String> mListFile = new ArrayList<>();
//第一步,遍历Assets文件夹
    private void assetsFile() {
        try {
            String[] i = getApplicationContext().getAssets().list("");
            //                Log.e(TAG, "onCreate: " + j );
            if (i.length > 0) {
//                Log.i(TAG, "assetsFile: 执行了没--" + i.length);
                for (String j : i) {
                    assetsFile_2(j);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

//第二部
    private void assetsFile_2(String path) {
        InputStream in = null;
        try {
            String[] i = getApplicationContext().getAssets().list(path);
            if (i.length > 0) {//path是目录
                for (String j : i) {
                    assetsFile_2(path + "/" + j);
                }
            }else{//是文件
                //如果文件的后缀是.css或js格式就就加入集合中
                if (path.endsWith(".css") || path.endsWith(".js")){
//                    Log.e(TAG, "assetsFile_2:-- "+ path);
                    mListFile.add(path);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

相关文章

网友评论

      本文标题:遍历assets中的所有文件夹,并把得到的文件放到List集合中

      本文链接:https://www.haomeiwen.com/subject/ncmnaqtx.html