Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In an iPhone Application, I just write one line to get the complete path for a specific file ( as below ).

NSString *strPath=[[NSBundle mainBundle] pathForResource:@"myjavascript" ofType:@"js"];

My question is How to get the complete path for a specific file which is located under Assets folder in Android.

Sample Image.

alt text

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
430 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assets are compiled into .apk file (which basically is zip file). You can't get system path into zip file. You have to manually unzip .apk to some folder and get file system path to asset folder and files inside that folder.

But it sounds like you don't really need a path to asset files. You should look into these functions:

Context.getAssets()
AssetManager.open(String fileName)
AssetManager.openFd(String fileName)

These functions allow you to get input stream or file descriptor for any of your assets. Here is an example:

AssetManager assetManager = getAssets();
InputStream assetIn = assetManager.open("excanvas.js");
//do something with assetIn...  

You need to specify path to your asset relatively to asset folder.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...