bufferedwriter not working in android
<p>i have a file that i have stored in my assets folder. i read the file and attach certain data to the file as per the user requirement. i then store the file into my emulator into the data directory.  i am using bufferedwriter for this purpose but it is not working and the resultant file made in the data folder has size 0kb. the file is being made.
here is my code</p>

<pre><code>InputStream myInput = this.getAssets().open("exportformat.txt");
        BufferedReader inputStream = new BufferedReader(
                new InputStreamReader(myInput));

        String outFileName = "/data/data/packagename/attachment.txt";
        OutputStream myOutput = new FileOutputStream(outFileName);
        BufferedWriter outStream = new BufferedWriter(
                new OutputStreamWriter(myOutput));
        String datafromfile;
        while ((datafromfile = inputStream.readLine()) != null) {
            StringBuffer sb = new StringBuffer(datafromfile);
            if (datafromfile.equals("DTSTART:"))
                sb.append(details[2]);
            if (datafromfile.equals("DTEND:"))
                sb.append(details[3]);
            if (datafromfile.equals("SUMMARY:"))
                sb.append(details[0]);
            if (datafromfile.equals("DESCRIPTION:"))
                sb.append(details[1]);
            datafromfile = sb.toString();

            outStream.write(datafromfile);
            outStream.newLine();
        }

        // Close the streams
        myOutput.flush();
        myOutput.close();
        outStream.close();
        inputStream.close();
        myInput.close();
    } catch (Exception e) {
            e.printStackTrace();
    }
}
</code></pre>

<p>i have tried debugging. the data is being correctly read , it is only the write operation that is not working.</p>

<p>thank you in advance.</p>

<p>ANSWER:</p>

<p>the following code is working:</p>

<pre><code>InputStream myInput = this.getAssets().open("exportformat.txt");
        BufferedReader inputStream = new BufferedReader(
                new InputStreamReader(myInput));

        String outFileName = "/data/data/com.helios.NauticDates/attachment.ics";
        File checkfile = new File(outFileName);
        if(checkfile.exists()){
            checkfile.delete();
        }
        for(int i =0 ;i&lt;4;i++){
            if(details[i].equals("null"))
                details[i]=" ";
        }
        FileOutputStream myOutput = new FileOutputStream(outFileName);
        String datafromfile;
        while ((datafromfile = inputStream.readLine()) != null) {
            StringBuffer sb = new StringBuffer(datafromfile);
            if (datafromfile.equals("DTSTART:"))
                sb.append(details[2]);
            if (datafromfile.equals("DTEND:"))
                sb.append(details[3]);
            if (datafromfile.equals("SUMMARY:"))
                sb.append(details[0]);
            if (datafromfile.equals("DESCRIPTION:"))
                sb.append(details[1]);
            if(datafromfile.equals("CATEGORIES:"))
                sb.append(details[4]);
            datafromfile = sb.toString();
            datafromfile+="\n";
             byte[] temp = datafromfile.getBytes();
             myOutput.write(temp);
        }

        // Close the streams
        myOutput.flush();
        myOutput.close();
        inputStream.close();
        emailintent.putExtra(Intent.EXTRA_STREAM,Uri.parse(outFileName));
        emailintent.setType("plain/text");
        startActivity(Intent.createChooser(emailintent, "Send mail..."));
    } catch (Exception e) {
            e.printStackTrace();
    }
</code></pre>
