Possible Duplicate:
Android - How to determine the Absolute path for specific file from Assets?
I am trying to pass a file to File(String path) class. Is there a way to find absolute path of the file in assets folder and pass it to File(). I tried file:///android_asset/myfoldername/myfilename
as path string but it didnt work. Any idea?
Unless you unpack them, assets remain inside the apk. Accordingly, there isn't a path you can feed into a File. The path you've given in your question will work with/in a WebView, but I think that's a special case for WebView.
You'll need to unpack the file or use it directly.
If you have a Context, you can use
context.getAssets().open("myfoldername/myfilename");
to open an InputStream on the file. With the InputStream you can use it directly, or write it out somewhere (after which you can use it with File).AFAIK, you can't create a
File
from an assets file because these are stored in the apk, that means there is no path to an assets folder.But, you can try to create that
File
using a buffer and theAssetManager
(it provides access to an application's raw asset files).Try to do something like:
Let me know about your progress.