to convert strings into text file
<p>I am working on an application in which I'll have to convert strings into text file.</p>

<p>These strings are being received from server. Can you please help me out? </p>

<p>My code is:                                           </p>

<pre><code>try {
     URL url = new URL("URL");
     URLConnection ucon = url.openConnection();
     InputStream is = ucon.getInputStream();
     BufferedInputStream bis = new BufferedInputStream(is);
     ByteArrayBuffer baf = new ByteArrayBuffer(50);
     int current = 0;
     while ((current = bis.read()) != -1) {
           baf.append((byte) current);
     }

     FileOutputStream fos = new FileOutputStream("/mnt/sdcard/random.txt");
     fos.write(baf.toByteArray());
     fos.close();
     File sdcard =  Environment.getExternalStorageDirectory(); 
     File file1 = new File(sdcard,"xyz.txt"); 
     File file2 = new File(sdcard,"random.txt"); 
     StringBuilder text = new StringBuilder(); 

     try { 
          BufferedReader br1 = new BufferedReader(new FileReader(file1));
          BufferedReader br2 = new BufferedReader(new FileReader(file2));
          String strLine1, strLine2;
          boolean isSame = true;
          StringBuilder finalText = new StringBuilder();
          strLine1 = br1.readLine();
          strLine2 = br2.readLine();
          if (strLine1.equals(strLine2)){
            Toast.makeText(getBaseContext(), strLine2,Toast.LENGTH_LONG).show();
          }else {
            isSame = false;
            Toast.makeText(getBaseContext(), strLine1,Toast.LENGTH_LONG).show();
            tv.setText(finalText.toString());
          }
     }finally {

}
</code></pre>
