Reading a file from external SD card in android Marshmallow 6.0.1 giving fileNotFoundException open failed: ENOENT
<p>I am trying to read a file from external SD card in android Marshmallow 6.0.1 and want to convert in Base64, but it is giving ENOENT(fileNotFoundException). But my same code is working for 6.0 and below. My code is as follows:</p>

<pre><code>private String convertFileToByteArray(File file) { //file path as: /storage/emulated/0/abc.doc
        byte[] byteArray = null;
        try {

            File f=new File(file.toString());
            Log.e("File EXISTs: &gt;&gt;",""+f.exists());

           //getting error in this line,giving fileNotFoundException
            FileInputStream inputStream = new FileInputStream(file); 
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024 * 11];
            int bytesRead = 0;

            while ((bytesRead = inputStream.read(b)) != -1) {
                bos.write(b, 0, bytesRead);
            }

            byteArray = bos.toByteArray();

            Log.e("Byte array", "&gt;" + byteArray);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return Base64.encodeToString(byteArray, Base64.NO_WRAP);
    }
</code></pre>

<p>Can any one suggest me what's wrong i am doing here. PS: I am giving runtime permissions also(read and write).</p>