如何确定从资产特定文件的绝对路径?资产、绝对路径、文件

由网友(起飞的纸飞机フ)分享简介:在一个iPhone应用程序,我只写一行来获取特定文件的完整路径(如下图)。In an iPhone Application, I just write one line to get the complete path for a specific file ( as below ).NSString *strPa...

在一个iPhone应用程序,我只写一行来获取特定文件的完整路径(如下图)。

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"];

我的问题是如何获得完整的路径位于在资产文件夹在Android中的特定文件

样本影像。

推荐答案

资产被编译成的.apk文件(这基本上是zip文件)。你不能得到系统路径为zip文件。您必须手动解压.apk文件到某个文件夹,让文件系统路径的资产的文件夹,文件夹里面。

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() < BR> AssetManager.open(字符串文件名) AssetManager.openFd(字符串文件名)

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.

阅读全文

相关推荐

最新文章