Opening a File from assets folder in android

前端 未结 6 994
面向向阳花
面向向阳花 2020-12-01 14:37

I have a .gif file inside the assets folder like this assets/Files/android.gif. when I try to open the file it throws an exception at the second line

AssetM         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 15:22

    I suspect you are getting complaints about unhandled exception type IOException. If that's the case, you need to put the call to mgr.open in a try-catch block to handle the exception that may occur when retrieving the InputStream object.

    AssetManager mngr = getAssets();
    try {
        InputStream is2 = mngr.open("Files/android.gif");
    } catch (final IOException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题