获取占用率大于70%的硬盘,准备写入oracle过程,在占比大于90%时,向指定邮箱发送邮件。
import java.io.File;
import java.text.DecimalFormat;
public class Diskfree {
public static void main(String[] args) {
File[] roots = File.listRoots();
// 获取磁盘分区列表
DecimalFormat df = new DecimalFormat("######0.00");
for (File file : roots) {
if(file.getTotalSpace()==0){
System.out.println(file.getPath()+"空的" );
}
else
{
double free=file.getFreeSpace();
double total=file.getTotalSpace();
double usePercent=(double)free/total*100;
if(usePercent>70){String usePercent2=df.format(usePercent);
System.out.println(file.getPath()+"盘使用率"+usePercent2+"%");}
}
}
}
}
import java.io.File;
import java.text.DecimalFormat;
public class Diskfree {
public static void main(String[] args) {
File[] roots = File.listRoots();
// 获取磁盘分区列表
DecimalFormat df = new DecimalFormat("######0.00");
for (File file : roots) {
if(file.getTotalSpace()==0){
System.out.println(file.getPath()+"空的" );
}
else
{
double free=file.getFreeSpace();
double total=file.getTotalSpace();
double usePercent=(double)free/total*100;
if(usePercent>70){String usePercent2=df.format(usePercent);
System.out.println(file.getPath()+"盘使用率"+usePercent2+"%");}
}
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9606200/viewspace-1803554/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9606200/viewspace-1803554/