Open top menu


Explain-  write Log file programmatically in android.


 
import android.content.Context;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;


public class LogClass {
    Context context;

    public LogClass(Context context, String text) {
       this.context=context;
        LogFile(text);
        DeletOlderFolder();
    }

    public  void LogFile( String text){

            File logFile = new File("sdcard/LoungeLogFile.txt");
            if (!logFile.exists()) {
                try {
                    logFile.createNewFile();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
            try {
                BufferedWriter buf = new BufferedWriter(

                                    new FileWriter(logFile, true));
                buf.append(text);
                buf.newLine();
                buf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

    }
 }
Tagged

0 comments