I’m developing a test class that have to check if there are all the resources. It’s a specification mandatory that i access to the resources by file name (png’s).
I know there’s the possibility of loading as a resource, but I cannot load resources. I’m developing a test app. How I could access the file file.png in res/drawable named ?
new FileOutputStream("/res/drawable/xxx.png");
It is recommended to read Resources Overview from Android docs,but if your problem is only about accessing resources,read Accessing Resources.So you can do what you want.
Summery,there is some ways to access resources that depends on situations,for example when you know name of resource or you know it’s ID.And also it depends that where you want to access resources.
In your case I guess that you want to access a
drawablein your code,if it is true,you can do like this:For example if name of your .png file is myimage and you have to set it in ImageView with name im do this:
Edit:
If you have to get an
InputStreamform a file in resources,you should consider creating arawfolder inside res directory and put your file in it and then call getResources().openRawResource(resourceName) from your Activity or widget.For example :Here your file that is in raw folder is for example
test.png.You can see more details here:
Using files as raw resources in Android
Android: Loading files from the Assets and Raw folders
stackoverflow
stackoverflow
stackoverflow
Finally if you want to create an output file from your resource,get an InputStream from it and write it’s content to an OutputStream,you can see a good example here.