Write Log in Text file in android

by Friday, August 01, 2014 0 comments

      public void appendLogger(String text)  
      {      
        File logFile = new File("/mnt/sdcard/log.file");  
        if (!logFile.exists())  
        {  
         try  
         {  
           logFile.createNewFile();  
         }   
         catch (IOException e)  
         {  
           // TODO Auto-generated catch block  
           e.printStackTrace();  
         }  
        }  
        try  
        {  
         //BufferedWriter for performance, true to set append to file flag  
         BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));   
         buf.append(text);  
         buf.newLine();  
         buf.close();  
        }  
        catch (IOException e)  
        {  
         // TODO Auto-generated catch block  
         e.printStackTrace();  
        }  
      }  

Unknown

Androider

Welcome to Android-Action Blog. I’m a normal guy, who is passionate about Mobile Coding. Here I am writing about Android. Happy learning

0 comments:

Post a Comment