Android FileOutputStream return FileNotFoundException in api level 22
<p>I am trying to download a pdf file from server. I write some code for that. It works fine for api level 21 and >=23 but not working on api 22. Here is the problem:</p>

<pre><code>OutputStream output = new FileOutputStream(fileName);
byte data[] = new byte[1024];

while ((count = input.read(data)) != -1) {
   output.write(data, 0, count);
}
</code></pre>

<p>But when it tries to execute </p>

<pre><code> OutputStream output = new FileOutputStream(fileName); 
</code></pre>

<p>it shows </p>

<pre><code>java.io.FileNotFoundException: /storage/emulated/0/data    /data/com.example.test/files/training/training.pdf: open failed: ENOENT (No such file or directory)
</code></pre>

<p>This works fine for api level 21 and 23. What went wrong? How can I solve this?</p>