LuckyScooby
LuckyScooby

Reputation: 91

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!

Upvotes: 2

Views: 735

Answers (2)

Tom C
Tom C

Reputation: 814

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:") );
        }
    }
}

Upvotes: 1

pacman
pacman

Reputation: 837

I think that the best solution is using SIGAR API https://support.hyperic.com/display/SIGAR/Home . It works for majority OS.

Upvotes: 1

Related Questions