Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find how much disk space is left using Java?

Tags:

java

diskspace

How to find how much disk space is left using Java?

like image 944
Roman Kagan Avatar asked Jun 26 '09 21:06

Roman Kagan


People also ask

How do I check my disk space left?

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.

How do I free up space in Java?

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.


1 Answers

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

like image 51
Kredns Avatar answered Sep 19 '22 12:09

Kredns