CD-Drive removing using Java API

343 Views Asked by At

How can I close the CD-ROM tray, using Java API or JNI?

Is it possible at all to interact with cd-drive (start burning, stop, make slower or faster rotation, etc)?

2

There are 2 best solutions below

0
Mike Kwan On

There is no built-in Java API to do this. The next best thing which people tend to do is to dump a script specific which will open/close the CD drive. This is often done with a VBS script as @Asad Rasheed has commented.

Since you ask for a JNI way of it we will also need to know what platform you are targetting. On Windows, however, you can use mciSendString() with something like:

mciSendString("set cdaudio door open", null, null, null);

If you want more control over which CD drive to open you might want to use some other function such as DeviceIoControl().

0
comrad On

On Linux/OSX that would be

Runtime.getRuntime().exec("eject");