javafiledvd

Is there a way to discern if a drive is a dvd/cd/blueray drive without a disc inside?


After looking at this question here: Get all DVD drives in Java

It seems to me that with JAVA 7 there is a way to discern between hard drives and dvd/cd drives when there is cd/dvd inside the drive. But that one method fails if the drive is empty.

My question is: Is there now 4 years later a method to discern which of the drives are hard drives and which are cd/dvd/blueray drives even if those drives have no cd/dvd/blueray inside?

Edit: The target OS for this is Linux


Solution

  • Can you run system commands, or must this be pure Java? If you can run system commands, try:

    Runtime.getRuntime().exec("more /proc/sys/dev/cdrom/info");
    

    This will give you something like:

    CD-ROM information, Id: cdrom.c 3.20 2003/12/17
    
    drive name:     sr0
    drive speed:        24
    drive # of slots:   1
    Can close tray:     1
    Can open tray:      1
    Can lock tray:      1
    Can change speed:   1
    Can select disk:    0
    Can read multisession:  1
    Can read MCN:       1
    Reports media changed:  1
    Can play audio:     1
    Can write CD-R:     1
    Can write CD-RW:    1
    Can read DVD:       1
    Can write DVD-R:    1
    Can write DVD-RAM:  1
    Can read MRW:       1
    Can write MRW:      1
    Can write RAM:      1
    

    For more comprehensive info, you could run:

    Runtime.getRuntime().exec("hwinfo --cdrom");
    

    In there should be a line like:

    Feature: CD-R, CD-RW, DVD-R, DVDRAM
    

    If you have a blu-ray drive in the system, I would expect BDROM, BD-ROM, BD-R, BD-RW or something similar