Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

List of disc devices in a system

Thread view: 
Lino - 31 Jul 2006 10:54 GMT
Hello,
With File.listRoots() I can get the list of roots (devices) in a
system. The problem I'm having is that I'm getting the DVD unit
although it was empty. Does anybody know how to know if the DVD unit is
empty? With File.exists() I can know it but a message box with the
error appears and I want to avoid the appearing of this box.
Thanks in advance.
Martin Lansler - 31 Jul 2006 21:03 GMT
Hi Lino,

Well I did not have any problems with my DVD drives, my floppy drive however
caused an error message to be displayed:

import java.io.File;

public class ListRoots {
   public static void main(String[] args) {
       File[] roots = File.listRoots();
       File[] ignoreRoots = new File[] { new File("a:\\") };
       listRoots: for (File file : roots) {
           for (File ignoreRoot : ignoreRoots) {
               if (file.equals(ignoreRoot)) {
                   System.out.println("[ignored]" + file);
                   continue listRoots;
               }
           }
           System.out.println((!file.canRead() ? "[not available]" : "") +
file);
       }
   }
}

Running the code above on a Windows XP gave:
[ignored]A:\
C:\
D:\
[not available]E:\
[not available]F:\
[not available]Z:\

So maybe a workaround would be to ignore the floppy drive as the code above
does - which roots to ignore could be configurable in your application.

Cheers,
Martin.

> Hello,
> With File.listRoots() I can get the list of roots (devices) in a
[quoted text clipped - 3 lines]
> error appears and I want to avoid the appearing of this box.
> Thanks in advance.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.