比如一个u盘是8G的,使用了1.5G
求未使用能有百分之多少写个方法

解决方案 »

  1.   

    public class Diskfree {
      public static void main(String[] args) {
      File[] roots = File.listRoots();//获取磁盘分区列表
      for (File file : roots) {
      System.out.println(file.getPath()+"信息如下:");
      System.out.println("空闲未使用 = " + file.getFreeSpace()/1024/1024/1024+"G");//空闲空间
      System.out.println("已经使用 = " + file.getUsableSpace()/1024/1024/1024+"G");//可用空间
      System.out.println("总容量 = " + file.getTotalSpace()/1024/1024/1024+"G");//总空间
      System.out.println();
      }
      }
      }  来源:考试大-计
      

  2.   

    double total = 8.0;
    double used = 1.5;
    double percent = used / total * 100; // 18.75
    double percent2 = used / total // 0.1875