File_Size - mayurparmar2/AlarmDemo GitHub Wiki
Post.java
/* get format File Size*/
public static String formatFileSize(long size) {
if (size <= 0) {
return "0 B";
}
final String[] units = {"B", "KB", "MB", "GB", "TB"};
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
deleteDir.java
/* deleteDir File*/
public boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}