Check for file existence in androids assets folder?

前端 未结 6 1254
不思量自难忘°
不思量自难忘° 2020-12-30 19:33

My app has .txt files in subdirectories in the assets folder. It reads those .txt files and puts them in a textview. It\'s working great and no problems.

Should I be

6条回答
  •  爱一瞬间的悲伤
    2020-12-30 20:15

    AssetManager am = getAssets();
    
        try {
            List mapList = Arrays.asList(am.list("path/in/assets/folder"));
    
            if (mapList.contains("file_to_check")) {
                Log.e("ERROR", "exists");
            } else {
                Log.e("ERROR", "not exists");
            }
        } catch ( IOException ex){
            ex.printStackTrace();
        }
    

    Convert to function or method can be easy ;)

提交回复
热议问题