File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to get the name of CD drive? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get the name of CD drive?" Watch "How to get the name of CD drive?" New topic

How to get the name of CD drive?

Jim Wang
Ranch Hand

Joined: Oct 04, 2001
Posts: 41
I have a servlet need to read PDF file from CD and I can get the name of file from the database. My problem is I don't know which name of the CD drive will be used later (d, e, f ...)? Since I can't make the CD drive's name hardcoded in my code, I wonder is there a way to figure it out from the system?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17281

Not every computer has exactly one CD drive, and Java doesn't have a lot of support for hardware sniffing, since that's not easy to do in a system designed for portability.
However, you can manually provide the drive ID via a servlet startup parameter and avoid hard-coding it in program logic. Or better yet, put the whole PDF path there, in case you need to move it later.

An IDE is no substitute for an Intelligent Developer.
Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
I agree with Tim.
The init parameter is a good idea, however, I would set up a property file of some sort that has the drive path in it (along with any other application properties), and create a class that reads from that file. This allows you to only have to change the property file when you create the web application on a new machine. The property files and their java counterparts (ResourceBundles) work on Windows, Linux, and Solaris machines. I am sure they would work on any other system that has an updated JVM.
Hope this Helps
I agree. Here's the link:
subject: How to get the name of CD drive?
It's not a secret anymore!