This question already has an answer here:
这个问题在这里已有答案:
- How to find how much disk space is left using Java? 6 answers
如何找到使用Java留下多少磁盘空间? 6个答案
I tried with File getFreeSpace() also which returns me 0. Is there any other way to do this?
我尝试使用File getFreeSpace()也返回0。有没有其他方法可以做到这一点?
4 个解决方案
#1
0
How about the older org.apache.commons.io.FileSystemUtils?
旧的org.apache.commons.io.FileSystemUtils怎么样?
#2
0
try {
double freeDiskSpace = org.apache.commons.io.FileSystemUtils.freeSpaceKb("/volume");
double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;
System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB);
} catch (IOException e) {
e.printStackTrace();
}
#3
0
Try
System{" df -k | awk '{sum += $4 }i; END {print sum} '"};
#4
0
public long getTotalSpace();
public long getFreeSpace();
public long getUsableSpace();
Each of these methods returns the requested size, in bytes, of the partition represented by the java.io.File or 0L if a partition cannot be obtained from the File object. Can you report your code?
如果无法从File对象获取分区,则这些方法中的每一个都返回由java.io.File或0L表示的分区的请求大小(以字节为单位)。你能举报你的代码吗?
#1
0
How about the older org.apache.commons.io.FileSystemUtils?
旧的org.apache.commons.io.FileSystemUtils怎么样?
#2
0
try {
double freeDiskSpace = org.apache.commons.io.FileSystemUtils.freeSpaceKb("/volume");
double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;
System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB);
} catch (IOException e) {
e.printStackTrace();
}
#3
0
Try
System{" df -k | awk '{sum += $4 }i; END {print sum} '"};
#4
0
public long getTotalSpace();
public long getFreeSpace();
public long getUsableSpace();
Each of these methods returns the requested size, in bytes, of the partition represented by the java.io.File or 0L if a partition cannot be obtained from the File object. Can you report your code?
如果无法从File对象获取分区,则这些方法中的每一个都返回由java.io.File或0L表示的分区的请求大小(以字节为单位)。你能举报你的代码吗?