Listing current devices on Linux box

I write a Java program that lists all devices available on a Linux box. Such devices are floppy, cdrom, memory stick (usb) etc. I don't have root privileges. Can I do that ? Are there any sample codes out there ? Any suggestions ?

Thanks.
LVL 1
kevinnguyenAsked:
Who is Participating?
 
objectsCommented:
without native code the best u can probably do is this

http://javaalmanac.com/egs/java.io/Roots.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Or you can use the Java communications API, I guess.
0
 
sciuriwareCommented:
You can catch the output from the mount command.

;JOOP!
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
sciuriwareCommented:
objects, that will give you only    /     on UNIX.

;JOOP!
0
 
sciuriwareCommented:
You can also read a file like /etc/fstab, but to find actual mounts, use mount as I said.

;JOOP!
0
 
sciuriwareCommented:
I believe I gave the only right answers:

"http://javaalmanac.com/egs/java.io/Roots.html"                         is definitively wrong,

"Or you can use the Java communications API, I guess."                is indeed a guess.


;JOOP!
0
 
girionisCommented:
I am not only suggesting solutions based on answers, several times I need to do it based on guesses (i.e. to guess if a comment would lead to a possible solution) if the user does not respond back with feedback. I believe all are valid comments:

objects' is, since in Unix everything is a file and you could find devices from the file system. The user said that (s)he is using Linux so AFAIK it is a valid answer.
mayankeagle's also since you could use the java comm api to find all devices in a linux box.
0
 
sciuriwareCommented:
I insist:
"http://javaalmanac.com/egs/java.io/Roots.html"  finds disk partition root directories.

On MSWindows this could be interesting (A:, C:, D:, E:, G:, K: ...)
On LINUX you get  "/"  and that's all; that's no use!

Even looking at mounted or mountable devices, as I suggested, is an incomplete solution.
If effect, only descending /dev would reveal all devices, but, only if you know the 'local implementation standards'.
I can live with guesses.
I politely suggest: split between mayankeagle and me and assign B level.

;JOOP!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.