简体   繁体   中英

fileinputstream throwing filenotfoundexception while trying to retrieve a bitmap in android

I am trying to retrieve a bitmap from internal memory but it works on older versions , not on newer versions of android.It throws a filenotfoundexception.

The code which i use is:

public Bitmap getImageBitmap(Context context,String name){
        //BufferedInputStream bis = null;
        FileInputStream fis=null;
        try{
//          FileInputStream fis = context.openFileInput(name);
//            File file = new File("filesdir", name);
              File myFile = new File (path_file+File.separator+name); 
            //byte [] mybytearray  = new byte [(int)myFile.length()];
            fis = new FileInputStream(myFile);
             //bis = new BufferedInputStream(fis);
                Bitmap b = BitmapFactory.decodeStream(fis);
                //fis.close();
                return b;
            }
            catch(Exception e){
                return null;
            }
          finally{
              if(fis!=null)
              {
                try {
                    fis.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
              }

          }

        }

The fileinputstream object fis throws a filenotfoundexception.please help!!

okay y you commented BufferedInputStream use it like this

File myFile = new File ( path+ File.separator + fname); 
                byte [] mybytearray  = new byte [(int)myFile.length()];
                FileInputStream fis = new FileInputStream(myFile);
                BufferedInputStream bis = new BufferedInputStream(fis);
                bis.read(mybytearray,0,mybytearray.length);

change variable names as peryour program

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM