unable to write and append the text file android
<p>I am trying to write a text file for logging in my app. When it comes to execution, there are READ-ONLY EXCEPTION and hence cannot write the text file. </p>

<p>only      file 1"  can be executed </p>

<p>Now using 5.0.1 </p>

<p>The below is my code : </p>

<pre><code>public static void writefile(String text  )
{
    File externalStorageDir =  new File (Environment.getExternalStorageDirectory().getAbsolutePath() +  File.separator  + "Download" );
    String fileName=  date() + ".txt" ;
    File dir = new File(externalStorageDir  ,  File.separator + "eyedebug"  );
    boolean statement = dir.exists() &amp;&amp; dir.isDirectory();
    if(!statement) {
        // do something here
        dir.mkdirs(); 
        System.out.println("file 1");
    } 


    File myFile = new File(dir.getAbsolutePath() ,  File.separator + fileName  );
    if(!myFile.exists()){
        try {
            myFile.createNewFile();
            System.out.println("file 2");
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    } 

    try
    {
        FileWriter fileWritter = new FileWriter(myFile.getName(),true);
        BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
        bufferWritter.append(text);
        bufferWritter.newLine();
        System.out.println("file 3");
        bufferWritter.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }



}
</code></pre>