日期:2014-05-20  浏览次数:20620 次

怎么编写程序来查U盘空间是否大于100M?
如题 求解

------解决方案--------------------
假如你的U盘在电脑上显示的是F盘
Java code
import java.io.*;
public class GetUdisk {
public static void main(String[] args)
{
    System.out.println(getUdisk());
}
public static String getUdisk()
{   String str=null;
    String dirName="F:/";
    File win=new File(dirName);
    if(win.exists())
    {
        long total=(long)win.getTotalSpace();
        long free=(long)win.getFreeSpace();
        Double compare=(Double)(1-free*1.0/total)*100;
        str="F:盘  已使用 "+compare.intValue()+"%";
    }
    return str;
}
}