How to find how much disk space is left using Java?
How will I know how much space I have left? To check the total disk space left on your Windows 10 device, select File Explorer from the taskbar, and then select This PC on the left. The available space on your drive will appear under Devices and drives.
Java uses managed memory, so the only way you can allocate memory is by using the new operator, and the only way you can deallocate memory is by relying on the garbage collector.
Have a look at the File class documentation. This is one of the new features in 1.6.
These new methods also include:
public long getTotalSpace()
public long getFreeSpace()
public long getUsableSpace()
If you're still using 1.5 then you can use the Apache Commons IO library and its FileSystem class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With