Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the Absolute path for specific file from Assets?

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

like image 509
Sagar Kothari Avatar asked Jan 20 '11 06:01

Sagar Kothari


People also ask

How do you find the absolute path?

The getAbsolutePath() method is a part of File class. This function returns the absolute pathname of the given file object. If the pathname of the file object is absolute then it simply returns the path of the current file object.

How do you get assets path in flutter?

Specifying assetsFlutter uses the pubspec.yaml file, located at the root of your project, to identify assets required by an app. Note: Only files located directly in the directory are included unless there are files with the same name inside a subdirectory (see Asset Variants).


1 Answers

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.

like image 108
inazaruk Avatar answered Nov 01 '22 10:11

inazaruk