简体   繁体   English

File.getFreeSpace() 没有返回正确的值

[英]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.我在我的应用程序中使用 Java 的 File class 中的file.GetFreeSpace()来确保在传输文件之前有足够的空间。 The path is a unc path that currently has ~5TB of free space on it.该路径是一个 unc 路径,当前有大约 5TB 的可用空间。 However when the above code is ran, the amount of space returned is only 713998336 Bytes (~680MB).但是,运行上述代码时,返回的空间量仅为 713998336 字节(~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.我将应用程序映射为使用不同的 unc 路径,该路径的可用空间介于 100MB 和 1GB 多一点之间(我正在添加/删除要测试的文件),并且应用程序报告了正确的可用空间量。

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.与此类似的 unc 路径: \\domain6\test\Scratch_Folder\其中 Scratch_Folder 是具有约 5TB 可用空间的 DFS 命名空间。 However when file.getFreeSpace executes, it is returning the free space for \\domain6\test\ which only has 670MB.但是,当file.getFreeSpace执行时,它会返回\\domain6\test\的可用空间,它只有 670MB。 Why would this happen?为什么会发生这种情况?

Sounds like a bug in your JVM.听起来像是 JVM 中的错误。 This feature is new to Java 6, can you try Java 6 update 25. When I run this for a UNC path with 9 TB free, I see 9 TB.此功能是 Java 6 的新功能,您可以尝试 Java 6 更新 25。当我为具有 9 TB 空闲空间的 UNC 路径运行此功能时,我看到 9 TB。

I found the issue, Java was returning the amount of free space in the root of the DFS.我发现了问题,Java 正在返回 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.不是 DFS 的实际文件夹(Scratch_Folder 显示为快捷方式),我找到了不包含快捷方式的文件夹的不同、更直接的路径。 pointed the application there instead and now it is working as expected.而是将应用程序指向那里,现在它按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM