Reputation: 41
My Asset structure is divided in folders and files. When I open a file I need to know if is a file or folder. I need to know is the asset path I'm accessing if a file or a folder.
I'm trying to access the file through a method I'm 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 right? Is there other way to know if the asset is file or a folder?
Thanks
Upvotes: 0
Views: 2985
Reputation: 7585
That is the wrong way to access your assets folder.
InputStream is = getAssets().open("subfolder/somefile.txt");
Android Assets with SubFolders
Upvotes: 1