LuckyScooby LuckyScooby - 1 year ago 69
Java Question

Detect hard disk activity in Java

I've done this before using C# (here), it worked perfectly for me, but now I intend to program it in Java.

I've searched through Oracle's tutorials and documentations for anything related, but no success.

Please, I have no idea of how I accomplish this.
Thanks in advance for the attention!

Answer Source

Expanding upon @Art_Rebels' answer; To use SIGAR it requires you add the the relevant .jars to your project and the relevant library which is dependent upon on your Operating System.

If you require help setting up SIGAR there are many posts which already exist on Stack Overflow and just a Google away, regardless if you require help just ask!

Once you have SIGAR correctly configured you can use the following snippet to display the disk usage for your C: drive

import org.hyperic.sigar.Sigar;

public class HardDriveUsage
    public static void main( String[] args ) throws Exception
        Sigar sigar = new Sigar();
        while (true)
            Thread.sleep( 1000 );
            System.out.println( sigar.getDiskUsage("C:") );