" بىلقۇت تورى
جاۋادا بەلگىلەنگەن ھۆججەتنى ئۆچۈرۈش،سىغىمىغا ئىرىشىش


 
/**
* بەلگىلەنگەن ھۆججەتنىڭ چوڭلىقىغا ئىرىشىش
*
* @param file file
* @return size
* @throws Exception
*/
private long getFolderSize(File file) throws Exception {
long size = 0;
try {
File[] fileList = file.listFiles();
for (File aFileList : fileList) {
if (aFileList.isDirectory()) {
size = size + getFolderSize(aFileList);
} else {
size = size + aFileList.length();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return size;
}

/**
* بەلگىلەنگەن ھۆججەتنى ئۆچۈرۈش
*
* @param filePath filePath
* @param deleteThisPath deleteThisPath
*/
private void deleteFolderFile(String filePath, boolean deleteThisPath) {
if (!TextUtils.isEmpty(filePath)) {
try {
File file = new File(filePath);
if (file.isDirectory()) {
File files[] = file.listFiles();
for (File file1 : files) {
deleteFolderFile(file1.getAbsolutePath(), true);
}
}
if (deleteThisPath) {
if (!file.isDirectory()) {
file.delete();
} else {
if (file.listFiles().length == 0) {
file.delete();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

/**
* بىرلىك ئايلاندۇرۇش
*
* @param size size
* @return size
*/
private static String getFormatSize(double size) {

double kiloByte = size / 1024;
if (kiloByte < 1) {
return size + "B";
}

double megaByte = kiloByte / 1024;
if (megaByte < 1) {
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
}

double gigaByte = megaByte / 1024;
if (gigaByte < 1) {
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
}

double teraBytes = gigaByte / 1024;
if (teraBytes < 1) {
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
}
BigDecimal result4 = new BigDecimal(teraBytes);

return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
}
}



BilQut 2020-01-28-01:35 تەستىقلىغان.