如何从资源文件获取URI? [英] How to get URI from an asset File?
问题描述
我一直在试图获得URI路径的资源文件。
I have been trying to get the URI path for an asset file.
uri = Uri.fromFile(new File("//assets/mydemo.txt"));
当我检查文件是否存在我看到文件不存在
When I check if the file exists I see that file doesn't exist
File f = new File(filepath);
if (f.exists() == true) {
Log.e(TAG, "Valid :" + filepath);
} else {
Log.e(TAG, "InValid :" + filepath);
}
有没有人告诉我怎么可以提到的绝对路径中存在的资源文件夹的文件
Can some one tell me how I can mention the absolute path for a file existing in the asset folder
推荐答案
没有对现有的资源文件夹的文件绝对路径。您的项目资产/
文件夹中的内容打包在APK文件。使用<一个href="http://developer.android.com/reference/android/content/res/AssetManager.html"><$c$c>AssetManager$c$c>获取对象的的InputStream
上的资产。
There is no "absolute path for a file existing in the asset folder". The content of your project's assets/
folder are packaged in the APK file. Use an AssetManager
object to get an InputStream
on an asset.
修改
要修复我下面的意见之一,资产的URL语法是文件:/// android_asset / ...
。(注:三个斜杠)
To repair one of my comments below, the URL syntax for assets is file:///android_asset/...
(note: three slashes).
这篇关于如何从资源文件获取URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!