Writing data to a file
<p>I want to create a folder from inside my app. Inside the folder, I want to create just one file (say <em>recents</em>) where the app will keep writing data line by line on each launch. </p>



<pre><code>private void saveForRecents(String phoneNumber) {
    //Need to open File and write the phonenumbers that has been passed into it
    try{    
        File mydir = getDir("recents", 0); 

        //Creating an internal dir;
        File fileWithinMyDir = new File(mydir, "recents"); 

        //Getting a file within the dir.
        FileWriter fw = new FileWriter(fileWithinMyDir.getAbsoluteFile());


        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(phoneNumber);
        bw.newLine();
        bw.flush();
        bw.close();

    }catch(Exception e){
        Toast.makeText(getApplicationContext(), "Failed to write into the file", Toast.LENGTH_LONG).show();
    }
}
</code></pre>

<p>How do I access the contents of the <em>recents</em> file that is inside my directory <em>mydir</em>? And I want to access the data line by line as I'm writing data line by line. I would really appreciate if someone took their time to explain me how to do it because I need to learn it. Also please let me know if I am doing something wrong.</p>
