List of disc devices in a system

Discussion in 'Java' started by Lino, Jul 31, 2006.

  1. Lino

    Lino Guest

    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.
     
    Lino, Jul 31, 2006
    #1
    1. Advertising

  2. 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.

    "Lino" <> wrote in message
    news:...
    > 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, Jul 31, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bichitra Patta nayak via .NET 247

    What is the difference between DISC and UUDI, When its is used

    Bichitra Patta nayak via .NET 247, Sep 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    925
    Bichitra Patta nayak via .NET 247
    Sep 15, 2004
  2. James
    Replies:
    1
    Views:
    402
    Bruce Barker
    Nov 3, 2005
  3. steve
    Replies:
    1
    Views:
    5,492
    brucie
    Nov 29, 2003
  4. Tom

    html on disc.

    Tom, Apr 4, 2004, in forum: HTML
    Replies:
    4
    Views:
    387
    Revd. Norle Enturbulata
    Apr 5, 2004
  5. Naveen Vaila

    "Windows CE Devices and Palm Devices Help Needed"

    Naveen Vaila, May 24, 2004, in forum: ASP .Net Mobile
    Replies:
    1
    Views:
    508
    Abraham Durairaj
    Jun 23, 2004
Loading...

Share This Page