繁体   English   中英

在android应用中创建用户活动的日志报告

[英]creating Log report of user activities in android app

我想在我的android应用程序中创建用户活动的日志报告,我正在android内部存储器中创建目录,还成功创建了记事本文件。 我需要在第一个屏幕中的不同屏幕中写入日志报告,我已经成功写入了,第二次记事本文件为空,这是我的代码

File mydir,f;
FileWriter writer;
SimpleDateFormat df;
String formattedDate;
Calendar c = Calendar.getInstance();    
    SimpleDateFormat df = new SimpleDateFormat("E yyyy-MM-dd 'at' hh:mm:ss a ");
    formattedDate = df.format(c.getTime());
    mydir = getApplicationContext().getDir("LogFile",
            Context.MODE_PRIVATE); // Creating an internal dir;
    if (!mydir.exists()) {

        mydir.mkdirs();
    } else {
        // FileWriter fileWriter;
        try {
            f= new File(mydir, "kiran.txt");
            writer = new FileWriter(f);


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
writer.append("User logged in at :"+formattedDate+"with     username="+username+" with password="+uPass+"\n");
writer.close();

FileWriter更改方法: writer = new FileWriter(f);

java.io.FileWriter.FileWriter(File file, boolean append) throws IOException

即:

File logFile = new File(getFileName());
FileWriter file = new FileWriter(logFile, true);

true :允许申请

您需要以附加模式打开文件,可以通过使用FileWriter构造函数来实现。

writer= new BufferedWriter(new FileWriter(your_file, true));

FileWriter true参数声明您的文件将以追加模式打开,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM