Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to detect drive letters in Windows machine?

  Asked By: Colleen    Date: Jun 23    Category: Java    Views: 1750

I have a question. I'm trying to make my java application to read all
data from one of my optical drives in Windows XP machine whenever it
has a disk inside. However, I can't find a way to pass a proper path
name to the application or detect drive letters and its path by java.
Does anybody know how to solve this issue?



3 Answers Found

Answer #1    Answered By: Luki Fischer     Answered On: Jun 23

You can solve  the problem using File class from java.io package.
It works with all kinds of paths. It has methods to find  out if you
are dealing with a file or directory. getAbsolutePath(path) gets
the absolute path, current path  using getPath() and list() gets the
directory listing.

Answer #2    Answered By: Dennis Hayes     Answered On: Jun 23

I'll try io package. I assume that java  has some kinds of package deal
with path  and directory sturcture, but I'm kinda new to java..so..
Anyway, thank you so much for your prompt response.

Answer #3    Answered By: Canan Kaya     Answered On: Jun 23

you can access the drive  letters in this way:

File[] roots = File.listRoots();

Didn't find what you were looking for? Find more on How to detect drive letters in Windows machine? Or get search suggestion and latest updates.