[Android Assets]: file or folder?

My object structure is divided into folders and files. When I open a file, I need to know if a file or a folder is. I need to know the path to the resource I am accessing if the file or folder.

I am trying to access a file using a method that I am implementing.

public int getFileType (String filepath)
{
    String PACKAGE_APP_NAME = /com/fake/android/app;
    File f = null; 

    try{
        //f = new File(new URI("file:///android_asset/" + JNI_CLASSES + "/" + filepath));   
        f = new File(new URI("file:///android_asset/" + filepath)); 
    }
    catch (URISyntaxException e) {}

    if (f == null)
    {
        Log.e("ResListMaker","File Object Is Null");
        return -1;
    }
    else if (!f.exists())
    {
        Log.e("ResListMaker","File Doesn't Exist");
        return -1;
    }
    else if (f.isFile())
    {
        Log.e("ResListMaker","Regular File");
        return 0;
    }
        else if (f.isDirectory())
    {
        Log.e("ResListMaker","Directory");
        return 1;
    }
    else
    {
        Log.e("ResListMaker","Unknown type");
        return -1;
    }
}

      

But always return file doesn't exist. Is the URI path correct? Is there another way to find out if a resource is a file or folder?

thank

0


source to share


1 answer


This is the wrong way to access your assets folder.

InputStream is = getAssets().open("subfolder/somefile.txt");



Android assets with subfiles

+1


source







All Articles