0

I have the below function which worked recently until I upgrade to API 32. Now the code seems to be incompatible for API 32. it is aborting the execution at line saying file not found.

'FileOutputStream fileOutputStream = new FileOutputStream(file);' // going to exception 

java.io.FileNotFoundException: /storage/emulated/0/Download/TnpVM==.jpg: open failed: EACCES (Permission denied) android.system.ErrnoException: open failed: EACCES (Permission denied) /storage/emulated/0/Download/TnpVM==.jpg: open failed: EACCES (Permission denied)

public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        try {
                            String fileName = response.headers().get("content-disposition").split("filename=")[1];
                            File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            File file = new File(path, fileName);
                            InputStream inputStream = response.body().byteStream();
                            FileOutputStream fileOutputStream = new FileOutputStream(file);
                            IOUtils.copyStream(inputStream, fileOutputStream);
                            fileOutputStream.close();
                            subscriber.onNext(new LocalFile(file.getAbsolutePath(), response.headers().get("content-type")));
                        }
                        catch (Exception ex){
                            subscriber.onError(ex.getCause());
                        }
                    }

Any idea on how to solve this issue?

mahen3d
  • 6,007
  • 13
  • 50
  • 97
  • 1
    is that same issue https://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android – shuabing Mar 08 '22 at 03:45

0 Answers0