Open disk player with Java, and without specifying the drive

Asked

Viewed 76 times

1

Wanted if possible a simple and quick way to open the disk drive without specifying the drive letter. There are several ways because I have seen.

  • Look at this question in Stackoverflow.

  • 3

    I usually pressed the button in front of the unit, at that time when the machines used these media. /s

1 answer

5


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

Script taken from Sozão, for Windows, command-line + Vbscript. Save as batch (.bat) itself calls the self-contained part in Vbscript:

eject 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, usually the distibutions already comes with the utility eject, that can be used directly in the shell or called by your application:

eject /dev/cdrom


We also have the project eject Open source Sourceforge if you want to see how it works:

http://eject.sourceforge.net/


All the proposals I’ve seen in Java (I confess I haven’t searched too hard) use help from something external, apparently due to lack of abstraction of the necessary layer in the different implementations of the VM.

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


If you need more details, edit your question by adding a tighter context so we can help you more.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.