SIGAR (full Name System Information Gatherer and Reporter, which is the Systems information Collection Report), provides an open source, cross-platform API for collecting computer hardware and operating system information (the API's underlying interface is written in C). This article shows you how to get disk information with the SIGAR API:
Package Com.ghj.packageoftest;import Org.hyperic.sigar.filesystem;import Org.hyperic.sigar.filesystemusage;import Org.hyperic.sigar.sigar;import org.hyperic.sigar.sigarexception;/** * Get disk information with SIGAR API * * @author Gaohuanjie */public Class Disktool {public static void main (string[] args) throws Sigarexception {SIGAR SIGAR = new SIGAR (); FileSystem [] Filesystemarray = Sigar.getfilesystemlist (); for (FileSystem Filesystem:filesystemarray) {System.out.println ("FileSystem dirName:" + filesystem.getdirname ()) ;//partition of the drive letter name System.out.println ("FileSystem devname:" + filesystem.getdevname ());//partition of the drive letter name System.ou T.println ("FileSystem typeName:" + filesystem.gettypename ());//File system type name, such as local hard disk, optical drive, network file system, etc. System.out.println ( "FileSystem systypename:" + filesystem.getsystypename ());//file system type, such as FAT32, NTFS System.out.println ("FileSystem Options: "+ filesystem.getoptions ()); SYSTEM.OUT.PRINTLN ("FileSystem Flags:" + FilesystEm.getflags ()); System.out.println ("FileSystem type:" + filesystem.gettype ()); Filesystemusage filesystemusage = null; try {filesystemusage = Sigar.getfilesystemusage (Filesystem.getdirname ()); } catch (Sigarexception e) {//when Filesystem.gettype () is 5 This exception occurs-the file system type is optical drive continue; } System.out.println ("Filesystemusage total:" + filesystemusage.gettotal () + "KB");//File system overall Size system . OUT.PRINTLN ("Filesystemusage free:" + filesystemusage.getfree () + "KB");//File system remaining size System.out.println ("files Ystemusage used: "+ filesystemusage.getused () +" KB ");//file system used size System.out.println (" Filesystemusage Avail: " + filesystemusage.getavail () + "KB");//File system available size System.out.println ("Filesystemusage files:" + filesystemusage. GetFiles ()); System.out.println ("Filesystemusage freefiles:" + filesystemusage.getfreefiles ()); System.out.println ("Filesystemusage diskreadbytes:" + filesystemusage.getdiskreadbytes ()); System.out.println ("Filesystemusage diskwritebytes:" + filesystemusage.getdiskwritebytes ()); System.out.println ("Filesystemusage diskqueue:" + filesystemusage.getdiskqueue ()); System.out.println ("Filesystemusage diskservicetime:" + filesystemusage.getdiskservicetime ()); System.out.println ("Filesystemusage usepercent:" + filesystemusage.getusepercent () * 100 + "%");//File System resource utilization system. Out.println ("Filesystemusage diskreads:" + filesystemusage.getdiskreads ()); System.out.println ("Filesystemusage diskwrites:" + filesystemusage.getdiskwrites ()); System.err.println ("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); }}}
【
0 min Download Sample project】
Get disk information with the SIGAR API