Win2000 and XP get a hard disk remaining space (call Windows command with Java)

xiaoxiao2021-03-06  15

Package tigers;

Import java.io. *;

PUBLIC CLASS TIGER19 {

Public static void main (string [] args) {try {for (CHAR C = 'a'; c <= 'z'; c ) {string dirname = c ": //"; long free, = getfreediskSpace (DIRNAME) ; If (FreeSpace! = -1) {long Number = Math.Round (FreeSpace / (1024.00 * 1024.00); System.out.Println ("< >>>>" DIRNAME "remaining space is:" number "MB");}}} catch (Exception e) {e.printStackTrace ();}} private static long getFreeDiskSpace (String dirName) throws Exception {String osName = System.getProperty ( "os.name"); if (! ("Windows XP") || OSName.Equalsignorecase ("Windows 2000"))) Return -1; String Command = "CMD EXE / C DIR" DIRNAME; // Operating System Command Process Process = Runtime.getRuntime (). EXEC (Command); // Execute the operating system command. if (process == null) return -1; BufferedReader br = new BufferedReader (new InputStreamReader (process.getInputStream ())); String line = ""; String lastLine = ""; while ((line = br.readLine () )! = null) {// Read in turn, but the purpose of the While loop is just the last line character. System.out.println (line); Lastline = line;} lastline = lastline.replaceAll (",", "); // removes the comma in the middle of the like 2, 146, 623, 488. String [] iTems = lastline.split (""); long freespace = -1; for (int i = (items.length - 1); i> 0; I -) {// start traversing from the last string . Try {FreeSpace = long.parselong (items [i]); break; // If you find the destination data, you jump out of the loop. } Catch (NumberFormatexception NFE) {Continue; // Skip is not a number of characters. }} Return FreeSpace;}}

result:

The volume in the drive C does not have a label. The serial number of the volume is the D44F-E6C7C: / directory

2004-10-26 17:56 0 autoexec.bat2004-10-26 17:56 0 config.sys2004-10-26 18:04

documents and settings2005-02-02 13:45 inetpub2004-10- 26 18:51 mysql2004-10-26 18:42 nvidia2005-02-07 17:10 program files2005-02-02 14:54 windows 2 file 0 bytes 6 Directory 4,155,437,056 Available byte < >>>> C: / remaining space is: 3963MB driver D does not have a label. The serial number of the volume is 4cc9-c042

D: / directory

2005-01-18 18:09

2002 Jay Chou The_one Taipei Concert 2005-01-18 18:08 2004 Sun Yanzi Changsha Concert 2005-01-24 15:41 Program Files2005-01-19 18:38 [Hundreds of Variety] Sun Yanzi 2004 Young Unlimited Beijing Concert BY 100KANVIP2005-01-08 11:31 Upper Volc Scrolls 3 Morning Wind 0 File 0 bytes 5 Contents 2, 146, 623, 488 Bytes < >>>> D: / Remaining space is: 2047MB driver E Volume is the serial number of the ENGLISH volume is 82FD-06B2

E: / directory

2004-10-27 12:12

Friends old friendly (six people) Season 1 2004-10-27 12:17 campaign20042004-10-27 12:18 lifewords2004-10-27 12:18 < Dir> Survival II2002-09-17 09:23 133,415 Ancient Greek mythology .CHM2004-10-27 13:12 Audio2004-10-29 12:46 bodyguard 2004-10-30 09:18 Seattle sleep night 2004-11-03 05:37 506, 143, 755 Rain - Hujiang Film English learning material - this material is for learning exchange and collection .rmvb2004-11-08 18:04 551, 582 Wyabdc.zip2001-10-04 22:03 Word_50002004-11-09 09:15 1,728 readme2.txt2004-11-09 09:15 132 download must be read.txt2004-11-10 11:53 air2004-11-10 11:53 < Dir> ZERO_8ISO2004-11-25 17:08 English 5 files 506, 830, 612 bytes 11 directory 1,382, 211,584 available bytes < >>> E: / remaining space to: 1318MB driver F is a Download Volume The serial number is a directory of 092E-C538F: /

2004-09-03 16:21

Linux2004-08-20 13:57 Downloads2004-08-20 14:09 Jinshan drug tyrant 2004-08-20 14:18 fedora2004-08- 20 15:27 CPQ6C2004-08-21 17:46 Bitan-Website 0 file 0 byte 6 directory 711, 237, 632 can be used < >>>> f: / remaining space is: 678MB driver G The volume is the serial number of the Bitan volume is 4A54-A685

G: / directory

2004-10-26 20:35

KindDiary_save2005-02-07 13:11 workspace2005-02-07 22:57 test2004-08-22 13:49 bitan2004-08-26 20 : 16 java2004-08-27 13:50 Eye-Lib2004-08-30 23:40 www_eleaf_org2004-09-17 19:52 ediaary2.53 0 file 0 byte 8 Catalog 3,166,339,072 Available bytes < >>>> g: / remaining space to: 3020MB driver H is the serial number of the MedIA volume is a directory of 8B7A-8A9AH: /

2004-12-23 03:16 212, 302, 277 Civilization Ancient Country - Egypt.rmvb2005-01-26 19:06

MTV2004-12-28 22:19 World No thief 2004-08-24 23:44 Movies2004-10-27 11:16 Music2004-11-11 19:03 Workspace 1 file 212, 302,277 bytes 5 directory 1,545,773,056 can be used < >>>> H: / remaining space is: 1474MB The volume in the drive I is the serial number of an Agel volume is CCA0-7211

I: / directory

2004-11-12 20:40

Program files2004-10-31 21:01 book2004-12-24 18:54 movies2004-10-02 01:31 1, 134, 237 creation song, D minor. MP32005 -01-22 14:28 48, 206 U970P8T1D129269F913DT20041221111283DT2004122111283DT20041221112832 20:12 music2004-08-22 20:13 pictrue2004-08-22 20:13 downlines2005-01-22 14: 28 51,172 U970P8T1D129270F913DT20041221112840.jpg2005-01-22 14:28 50,043 U970P8T1D129271F913DT20041221112843.jpg2004-08-27 18:24 papa2004-09-21 19:18 wendang2004-10-10 11:57 english 4 Document 1,283,658 bytes 9 directory 2,524,266,496 available bytes < >>>> i: / remaining space to: 2407MB driver J is a SAVE volume serial number is a directory of B879-DD51J: /

2004-10-26 18:10

ghost-save2004-09-19 16:29 bitan2004-10-30 10:37 walking through the US video 2004-09-29 19:35 Linux2005-01-27 15:55 ghost2005-01-31 17:51 3D animation 2005-01-31 17:54 with earth peers 2005-01-31 17:58 Beasts 0 files 0 bytes 8 directory 3,276,644,352 Available bytes < >>>> J: / Remaining space is: 3125MB driver K is the serial number of the JavaWork volume is 05FA-1A24

K: / directory

2004-09-16 12:02

Eclipse3.02004-12-24 18:59 PAPA2004-11-29 19:26 myeclipse2003-08-12 14:08 ant2004-11- 14 01:05 togetherec2004-10-26 18:22 J2SE2004-11-25 15:27 program files2004-12-12 16:33 Webservices2004-09-20 04:40 < Dir> jboss2005-02-01 09:35 sqlserver2004-12-16 20:24 Eclipse2004-12-09 19:57 jdonsrc2004-12-12 20:39 apache22004-06- 17 21:09 Tomcat52004-12-31 12:19 Tiger2005-01-30 19:07 hibernate2005-02-02 13:21 merak2005-02-01 11:54 TEST252004-10-29 15:14 Tomcat2004-10-26 20:38 kinddiary_save2004-10-27 09:33 workspace2004-10-27 13:35 web-src2004-10 -30 09:20 books 0 files 0 bytes 23 directorys 320, 792, 576 Available bytes < >>> K: / remaining space to: 306MB driver L is the serial number of the backup volume is 4778-a427l: /

2004-12-12 17:19

Oracle 0 file 0 bytes 1 directory 2,883,919,872 Available bytes < >>>> L: / remaining space is: 2750MB

转载请注明原文地址:https://www.9cbs.com/read-46479.html

New Post(0)