Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems to find the CDRom

Status
Not open for further replies.

Kostarsus

Programmer
Nov 30, 2000
86
DE
Hello,

I want to write a application, which reads the data of the CD-Rom.
Today many computers have more than one CD-Rom.
I want to use a combobox where the user can select the right CD-ROM. I don't want to show the drives which aren't a CD-Rom.
In the File-Class I found a Method to extract all drives from system. This method is called listRoots(). The method copies all drives in an array of File-Class.
I have the problem that everytime I use a method of the File-Class, on the index in the array of listRoots(), which points to the floppy-disk-drive, I get a messagebox, that the drive can't be read. This is no exception because in a universal try-block, the debugger don't jump in the case-block.
Is there any way to suppress this messagebox?

Here a code-example:
try{
for (int i=0; i<myFileroots.length;i++){
if (myFileroots.canWrite()==true)
System.out.print(myFileroots.toString());
}
}
catch(Exception e){
System.out.print(e.getMessage());
}

My floppy-disk-drive is on index 0. So the first time, the if-clause is called, the messasgebox appears.

In reguards
Kostarsus
 
Its a bit of a hack but it works...

File[] fs = File.listRoots();
for (int i = 0;i < fs.length; i++) {
File f = fs;
if (!f.getPath().equals(&quot;A:\\&quot;) && !f.getPath().equals(&quot;B:\\&quot;)) {
if (f.canWrite()) {
System.out.print(f.toString());
}
}
}

scrat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top