Search code examples
androidfileinputstream

FileInputStream FileNotFoundException


I'm working with a library and I need to get a file path stored at raw folder, so library methods create a FileInputStream, but I always get a FileNotFoundException from library methods.

So I have created a class and try:

String path = "android.resource://" +context.getPackageName () + "/" + "myFileName"; 
InputStream fis2 = getResources().openRawResource(R.raw.myFileName);
File f = new File(path);

fis2 and f are correctly created and I get no FileNotFoundException.

But when I try: FileInputStream fis = new FileInputStream(path); I get the FileNotFoundException.


Solution

  • I need to get a file path stored at raw folder

    That is not possible, as it is not a file.

    so library methods create a FileInputStream

    Those library methods need to be adjusted to work with an ordinary InputStream. Then, use your fis2 InputStream.