Search code examples
javaunc

File.getFreeSpace() Not returning correct value


I use file.GetFreeSpace() from Java's File class in my application to make sure that there is enough room before transferring files. The path is a unc path that currently has ~5TB of free space on it. However when the above code is ran, the amount of space returned is only 713998336 Bytes (~680MB).

I mapped the application to use a different unc path that had in between 100MB and a little over 1GB free (I was adding/removing files to test) and the application reported the correct amount of free space there.

UPDATE: Through much debugging, I have found the issue. The unc path similar to this: \\domain6\test\Scratch_Folder\ where Scratch_Folder is a DFS namespace with ~5TB of free space. However when file.getFreeSpace executes, it is returning the free space for \\domain6\test\ which only has 670MB. Why would this happen?


Solution

  • I found the issue! Java was returning the amount of free space in the root of the DFS, not the actual folder of the DFS (the Scratch_Folder was showing up as a shortcut). I found a different, more direct path to the folder that didn't contain the shortcut, pointed the application there instead and now it is working as expected.