Determining filetype of file in assets folder

Posted by ChaimKut on Stack Overflow See other posts from Stack Overflow or by ChaimKut
Published on 2010-06-09T21:39:03Z Indexed on 2010/06/09 21:42 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

Question: How do you programmatically distinguish between directories and regular files in the assets folder?

When using AssetManager to access files in the assets folder, it seems impossible to determine if a file is in fact a file or a directory. You get the list of files from the list method and then open the file using the open method. I thought perhaps using the openFd method to get the asset file descriptor (and then subsequently requesting the normal file descriptor) would provide me some information. But requesting the file descriptor for a directory results in an IOException (which makes sense since what would it mean for a directory to have a file descriptor...?).

Currently I'm relying on that IOException (resulting from attemptng to open a directory in the assets folder) in order to determine if a file is in fact a directory. (Opening a regular file works just fine). This seems like a bad idea. Any other suggestions to distinguish between a file and a directory?

© Stack Overflow or respective owner

Related posts about android

Related posts about directory