Open top menu






In this tutorial explain how to Create / Delete Multiple text file Inside Root Folder  and every text file Size is 5Mb .

private File createEVENTFileWriter() {

    File filelog = null;

    try {

        String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root + "/" + log_foldereventname);
        myDir.mkdirs();
        String h = DateFormat.format("MM-dd-yyyyy ss",System.currentTimeMillis()).toString();
        filelog = new File(myDir, log_filenameevent);
        filelog.createNewFile();
        long fileSizeInBytes = filelog.length();
        long fileSizeInKB = fileSizeInBytes / 1024;

        if (fileSizeInKB > 5000) {

            File from = new File(myDir, log_filenameevent);
            File to = new File(myDir, h + log_filenameevent);
            if (from.exists()) {
                from.renameTo(to);

            }
        }

    } catch (Exception err) {
        fileWriteCreationFailed = true;
        err.printStackTrace();
    }
    return filelog;

}
 

public void DeletOlderFolder() {
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir =
new File(root + "/" + log_foldereventname);
    myDir.mkdirs();
    File list[] = myDir.listFiles();
   
for (int i = 0; i < list.length; i++) {
       
long diff = new Date().getTime() - list[i].getAbsoluteFile().lastModified();
       
if (diff >  3 * 24 * 60 * 60 * 1000) {//3 * 24 * 60 * 60 * 1000(3days)
           
list[i].getAbsoluteFile().delete();
        }
    }
Tagged

1 comment:

  1. Wynn casino reopens - Goyangfc
    Las Vegas-based Wynn Resorts has 스포츠사이트 announced that it will reopen 골인 벳 먹튀 its casino 플레이포커 at the 폰타나 벳 end of September. 폴댄스도끼 The resort opened at Encore in

    ReplyDelete