USB flash Drive Discovery device
PackageCom.lx.io;ImportJava.io.File;ImportJava.io.IOException;ImportJava.util.ArrayList;ImportJava.util.Arrays; Public class usbreadfile {/** * More information Welcome to the Kay Academy website: http://kaige123.com * @author Small Mo * * Public static void USB() {file[] files = file.listroots ();//List all current drive characters //Prepare the collection and add all the drive letter data.Arraylist<file> F1 =NewArraylist<> (); arraylist<file> F2 =NewArraylist<> ();LongSum//drive letter Total size LongSurplus;//Drive symbol remaining size LongUse//drive letter already used size while(true) {file[] newfiles = File.listroots ();//Get to new drive letter if(Newfiles.length > Files.length) {//If the new drive letter is greater than the original drive letter //Use the Arrays tool to convert an array to a collection in addition to the collectionF1.addall (arrays.aslist (Files)); F2.addall (Arrays.aslist (newfiles)); F2.removeall (F1);//Find the same data in F2 and F1 to delete for(File file:f2) {Try{Char[] C = File.getpath (). ToCharArray ();//Split the path into charactersSystem.out.print ("Insert:"+ c[0] +"Disk"); sum = File.gettotalspace ()/1024x768/1024x768/1024x768; surplus = File.getusablespace ()/1024x768/1024x768/1024x768; use = Sum-surplus;//list information for each drive letterSystem.out.println (c[0] +"Disk Total size:"+ Sum +"G"+"Remaining:"+ Surplus +"G"+"used:"+ Use +"G");//Use the runtime method to open the inserted USB flash driveRuntime.getruntime (). EXEC ("cmd/c Start"+ File.getpath ());}Catch(IOException e) {E.printstacktrace ();}} Files = newfiles;//Update drive letter}Else if(Newfiles.length < Files.length) {//If the new drive letter is less than the original drive letter //indicates that the USB drive has been unpluggedSystem.out.println ("USB Stick Unplugged"); files = Newfiles;}}}Public static void main(string[] args) {USB ();}}
USB flash Drive Discovery device