Java detect pendrive in Ubuntu with file.listFiles() -


I am using a thread so that the pandroid has been condomed or not, between two states / / P>

  @ Override goes public zero () {running = true; While (current) {// always try {delay. DrivePath = getDrivePath (pathpath); If (isReady () & amp; Drive path == faucet) {Notify (DriveState.EMPTY); } Else if (! IsReady () & Drive path! = Null) {Notify (drivestate.reddy); }} Hold (exception e) {e.printStackTrace (); }}} Private string getDrivePath (string pathpath) {file file = new file (path path); If (SystemUtils.IS_OS_WINDOWS) {return file.exists ()? Route Path: Empty; } Else {for (File: file.listFiles ()) {if (! F.getName (.) Equal to ignoreCase ("cdrom")} {return f.getAbsolutePath (); // we 'cedorum'}}}} return the first folder other than blank null; }  

This works very well in Windows with rootpath = "E: \", but it does not work in Ubuntu rootpath = "/ media / Ubuntu", odd The point is that I still do not understand that if I open pendrive in the file manager, then it works fine , but as soon as the plug-in is plugged in as a PdView , As if the user browses the file file manager what can i do Am I

There are two commands on a Linux machine I can think of which device you give useful information about Has been plugged in. The first is lsusb . When I run it on my machine: <00> Device 003: ID 8086: 0189 Intel Corp Bus 002 Device 021: ID 0718: 061A Impaction Corp Bus 002 Device 002: ID 8087: 0024 Intel Corp Integrated Rate Matching Hub ...

The second line is my pen drive is another command dmesg [148541.700254] SD 8: 0: 0: 0: [SDB] Enclosed SCSI removal Qualified disc [148830.993250] USB 2-1.2: USB disconnect, device number 21 [148836.316642] USB 2-1.2: AHC-PCI [148836.415145] New High-speed USB device number 22: New USB device found, ID vendor = ..., IDPProject = .... [148836.415157] USB 2-1.2: New USB device string using USB 2-1.2: MFR = 1, Product = 2, Serial Number = 3 [148836.415162] USB 2-1.2: Product: iPhone [148836.415167] USB 2-1.2: Manufacturer: Apple Inc. [148836.415171] USB2-1.2: Serial Number: .... [148836.894819] ipheth 2-1.2: 4.2: Apple iPhone USB Ethernet Device is Attached

You can use any of these commands You can set your program to choose or parse the output ie Runtime.getRuntime (). Executive ("dmesg)" .

I look at this solution around a work and I think the money in other possible ways of finding the USB drive while connecting is money.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -