I have some android project and I am trying to read some file from the "res/drawable-xhdpi" directory so I put
InputStream is = null;
try {
is = getResources().openRawResource(R.drawable.my_btn); //my_btn is inside drawable-xhdpi directory
} catch (Exception e) {
e.printStackTrace();
}
but I get
error opening trace file: No such file or directory
How can I deal with this issue. I tried to read this directly from FileInputStream
with an absolute path, then I realized that the root from which the files are fetched is the root of the JVM
so I still got the same No such file or directory
error message
Update :
I added an assets
directory in side src/main
, then I put my_btn.png
inside it then I call inside my MainActivity
class
InputStream is = null;
try {
is = getAssets().open("my_btn.png");
} catch (Exception e) {
e.printStackTrace();
}
but I still get the same error