如何让资源文件夹中的android文件路径 [英] how to get file path of asset folder in android

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

问题描述

我已经习惯了从Android应用程序的资源文件夹中的PNG图片传输到我的本地服务器上的Andr​​oid应用程序。我需要获得图像的资源文件夹的路径,请参考下我的code,

I have an Android application used to transfer the .png image from asset folder of Android application to my local server. I need to get the path of image in asset folder, pls refer my code below,

String stringPath = "android.resource//"+getPackageName()+"/raw/sample/logout.png";             
File f = new File(stringPath);

如果我用上面的code我有的文件未发现异常。因此,如何在资源文件夹图片路径?

If I use the above code I got "File not found exception". So how to take image path in asset folder?

推荐答案

尝试:

file:///android_asset/raw/sample/logout.png

如果你有一个背景下,你可以使用 context.getAssets()。打开(原始/采样/ logout.png)来打开的InputStream 上的文件。

If you have a Context, you can use context.getAssets().open("raw/sample/logout.png") to open an InputStream on the file.

这篇关于如何让资源文件夹中的android文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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