如何确定从资产特定文件的绝对路径? [英] How to determine the Absolute path for specific file from Assets?

查看:126
本文介绍了如何确定从资产特定文件的绝对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个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> <一href="http://developer.android.com/reference/android/content/res/AssetManager.html#open%28java.lang.String%29"相对=nofollow> AssetManager.open(字符串文件名)
<一href="http://developer.android.com/reference/android/content/res/AssetManager.html#openFd%28java.lang.String%29"相对=nofollow> 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.

这篇关于如何确定从资产特定文件的绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆