Open disk reader with Java, and without specifying the drive

1

I wanted a simple and quick way to open the disc player if possible without specifying the drive letter. There are several ways I've seen it.

    
asked by anonymous 28.03.2015 / 15:56

1 answer

5

Not directly in Java, but these alternatives can be called as an external application using exec() :

Script taken from SOzão , for Windows, in command line + VBScript. Save as batch (.bat) it even calls the auto-contained part in VBScript:

ejetar.bat

:sub echo(str) :end sub
echo off
'>nul 2>&1|| copy /Y %windir%\System32\doskey.exe '.exe >nul

'& cls
'& cscript /nologo /E:vbscript %~f0
'& pause

Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection

if colCDROMs.Count >= 1 then
        For i = 0 to colCDROMs.Count - 1
                colCDROMs.Item(i).Eject
        Next ' cdrom
End If


If you need to do the same in linux, generally the distributions already come with the eject utility, which can be used directly in the shell or called by your application:

eject /dev/cdrom


We also have the eject project in SourceForge, open source if you want to see how it works:

link


All the proposals I've seen in Java (I confess I have not looked too much) use help from something external, apparently for lack of layer abstraction required in the different implementations of the VM.

Here, another link that uses VB , this time generated by the java itself. But like any external tool, it depends on the OS.


If you need more details, please edit your question by adding a more restricted context so that we can help you further.

    
28.03.2015 / 18:58