Here you can find the source of getFreeSpace(File file)
public static long getFreeSpace(File file)
//package com.java2s; /*// w w w.ja va 2s. c om * Copyright Gergely Nagy <greg@webhejj.hu> * * Licensed under the Apache License, Version 2.0; * you may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 */ import java.io.File; public class Main { /** @return free space available on the partition for the specified file */ public static long getFreeSpace(File file) { long free = file.getFreeSpace(); while (free == 0) { file = file.getParentFile(); } return free; } }