Android: How to detect a directory in the assets folder?

前端 未结 9 1339
无人及你
无人及你 2021-01-05 18:15

I\'m retrieving files like this

String[] files = assetFiles.list(\"EngagiaDroid\"); 

How can we know whether it is a file or is a director

9条回答
  •  暖寄归人
    2021-01-05 18:51

    I've discovered this variant:

    try {
        AssetFileDescriptor desc = getAssets().openFd(path);  // Always throws exception: for directories and for files
        desc.close();  // Never executes
    } catch (Exception e) {
        exception_message = e.toString();
    }
    
    if (exception_message.endsWith(path)) {  // Exception for directory and for file has different message
        // Directory
    } else {
        // File
    }
    

    It's a more faster as .list()

提交回复
热议问题