Android 如何访问其他apk的assets文件夹下的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12387637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:31:57  来源:igfitidea点击:

How to access files under assets folder of other apk's?

androidandroid-assets

提问by AndroidDev

When we browse any apk we found there is one folder named assets. Now I want to access that folder programatically. so how should I proceed for that? (Input for the program will be apk file/just app name).

当我们浏览任何 apk 时,我们发现有一个名为 assets 的文件夹。现在我想以编程方式访问该文件夹。那我应该怎么做呢?(程序的输入将是 apk 文件/只是应用程序名称)。

回答by Nermeen

This will list all the files in the assets folder:

这将列出资产文件夹中的所有文件:

AssetManager assetManager = getAssets();
String[] files = assetManager.list("");

This to open a certian file:

这是打开一个证书文件:

InputStream input = assetManager.open(assetName);

回答by Santosh

If you want to access file from assets folder use the following code:

如果要从资产文件夹访问文件,请使用以下代码:

InputStream is = getAssets().open("contacts.csv");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(is);
HttpContext localContext = new BasicHttpContext();
HttpResponse response =httpClient.execute(httpGet, localContext);
BufferedReader reader = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));

回答by Santosh

For example: If you have the .ttf file in your assets folder: then you used like this:

例如:如果您的资产文件夹中有 .ttf 文件:那么您使用如下:

Typeface font = Typeface.createFromAsset(getAssets(), "MARKER.TTF");

Here is link: http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromCode

这是链接:http: //developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromCode