JAvaでディスクの空き容量を取得する



import java.io.File;
import java.util.Map;
import java.util.TreeMap;

public class CommonUtils {
	
	private static Map<String, String> map;
	
	/**
	 * @return Map<String, String>: key:    , value:      
	 */
	public static Map<String, String> getHdInfo() {

		map = new TreeMap<String, String>();
		
		File[] roots = File.listRoots();
		double unit = Math.pow(1024, 3);

		for (int i = 0; i < roots.length; i++) {
			
			String hd = roots[i].getPath();
			
			double freespace = roots[i].getFreeSpace() / unit;
			
			freespace = Math.ceil((freespace * 10)) / 10;
			
			map.put(hd, String.valueOf(freespace));
		}
		
		return map;
	}
}