File.getFreeSpace()
works if the file exists in the specified location. For example:
File file = new File("D:\\1\\1.txt");
System.out.println(file.getFreeSpace());
will print out the free space remaining on Drive D only if 1.txt exists in the directory 1 in drive D. If not, this returns a 0. Maybe you can create a temporary file in the directory to query the free space and delete once you have it.