How to Create Multiple Text File in android
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();
}
}
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();
}
}