11 Haziran 2014 Çarşamba

Android text dosyaya yazdırma

public void appendLog(String text)
    {       
       File logFile = new File("sdcard/log.txt");
       if (!logFile.exists())
       {
          try
          {
             logFile.createNewFile();
          } 
          catch (IOException e)
          {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }
       }
       try
       {
          //BufferedWriter içinde  true ile ekleme modu aktif
          BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
          buf.append(text); //yazidirma
          buf.newLine(); //alt satira geçiş
          buf.close();
       }
       catch (IOException e)
       {
          // TODO Auto-generated catch block
          e.printStackTrace();
       }
    }
-----------------------------------------------------------------------------

0 yorum :