How to know if a CD is inserted in the cdrom drive from java ?

T

Toni

I would like to know if there is a way to handle the cdrom drive from
java,
like to know if a CD is inserted and maybe know some specifications
about the cd inserted like if it contains data or if it is CD-R or
CD-RW.Thank you.
 
T

Thomas Weidenfeller

Toni said:
I would like to know if there is a way to handle the cdrom drive from
java,

No, not without native code. This is almost an FAQ.

Which reminds me, I don't know the current state of this group's FAQ. I
haven't seen one posted for a long time.

/Thomas
 
G

Greg Smith

I would like to know if there is a way to handle the cdrom drive from
java,
like to know if a CD is inserted and maybe know some specifications
about the cd inserted like if it contains data or if it is CD-R or
CD-RW.Thank you.

check out the JMF - Java Media Framework. It has stuff for animation,
graphics, MP3, etc... there are native libs for windows. i dont know
if it accesses cdroms directly. let us know...

greg
ps - JMF is available at
http://java.sun.com/products/java-media/jmf/index.jsp
 
A

Andrew Thompson

Which reminds me, I don't know the current state of this group's FAQ.

This one?
<http://www.afu.com/javafaq.html>

This is the closest I've ever come to discovering the
'official' FAQ of this group.

It's dead.
..I haven't seen one posted for a long time.

Links to my Java FAQ have taken the place of most of the old
broken links in the Mini-FAQ sent to c.l.j.p/c.l.j.h., but
it is not an FAQ well suited to posting as text.
 
T

Thomas Weidenfeller

Andrew said:
This one?
<http://www.afu.com/javafaq.html>

This is the closest I've ever come to discovering the
'official' FAQ of this group.

It's dead.

I know it's dead. Remember, I tried to convince Roedy to use his contact
to Peter to ask him about the future of this FAQ and if Peter doesn't
want to do anything with it to release it to another maintainer. Answer:
deadly silence.
Links to my Java FAQ have taken the place of most of the old
broken links in the Mini-FAQ sent to c.l.j.p/c.l.j.h., but
it is not an FAQ well suited to posting as text.

You can change that :) And don't forget to provide WinHelp, TeX,
DocBook, XHTML, Word, JavaHelp, RTF, PDF, ASCII, and troff versions of
it :)))

/Thomas
 
T

Toni

Hi guys,
check out the JMF - Java Media Framework. It has stuff for animation,
graphics, MP3, etc... there are native libs for windows. i dont know
if it accesses cdroms directly. let us know...

Well I checked JMF quickly but I could not find anything related to
this topic. I am using those lines to see if a CD is in the drive or
not but nothing more.

String deviceName = "Z:\\"; // Z is the letter of my cd-drive
File deviceFile = new File(deviceName);
if (deviceFile.exists())
System.out.println("CD is loaded");
else
System.out.println("CD is NOT loaded");

But this fails if a cd is there and it is empty, so this does not help
much. I need something more precise that can check if cd is empty, cd
has data, or no cd. Anybody has any ideas that enable me to do
something like this.
 
A

Andrew Thompson

String deviceName = "Z:\\"; // Z is the letter of my cd-drive

Is this for your personal use, or for other users as well?

That is an important point to establish as this is much easier
to achieve for a single user than ..anybody.

In any case you should probably search for it through the ..
File.listRoots()
File deviceFile = new File(deviceName);
if (deviceFile.exists()) {
System.out.println("CD is loaded");
File[] files = deviceFile.list();
for (int ii=0; ii<files.length; ii++) {
System.out.println( "File " + ii + ":\t " + files[ii] );
}
}
else
System.out.println("CD is NOT loaded");

But this fails if a cd is there and it is empty, ..

Read the Javadocs for File, all of them.
<http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html>
 
T

Tony Morris

boolean cd = JOptionPane.showConfirmDialog(null, "Is there a CD in there?
Tell the truth now.") == JOptionPane.YES_OPTION;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top