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 / February 2006

Tip: Looking for answers? Try searching our database.

volume label

Thread view: 
mike - 10 Feb 2006 23:20 GMT
Is there any way to get the volume label name in java of a certain
drive.  This would be for a program that I would run in Windows XP.  Of
if anyone has a suggestion of a better way to do this, I am wanting to
find out if a certain usb drive is plugged into the computer.  I just
figured that the best way to test it would be to check the label,
because the label shouldn't be changing.  

Any ideas?

Mike
Thomas Fritsch - 11 Feb 2006 01:38 GMT
> Is there any way to get the volume label name in java of a certain
> drive.  This would be for a program that I would run in Windows XP.  Of
> if anyone has a suggestion of a better way to do this, I am wanting to
> find out if a certain usb drive is plugged into the computer.

You can use
   File[] roots = File.listRoots();
I get {C:\, D:\, E:\} when my USB-stick is plugged in, and {C:\, D:\} when
it is plugged off.

Or you can use
   boolean b = (new File("E:\\")).exists();
I get true when my USB-stick is plugged in, and false when it is plugged
off.

> I just
> figured that the best way to test it would be to check the label,
> because the label shouldn't be changing.

Signature

"TFritsch$t-online:de".replace(':','.').replace('$','@')

Roedy Green - 11 Feb 2006 03:04 GMT
On Sat, 11 Feb 2006 02:38:05 +0100, "Thomas Fritsch"
<i.dont.like.spam@invalid.com> wrote, quoted or indirectly quoted
someone who said :

> I am wanting to
>> find out if a certain usb drive is plugged into the computer.

another way to do that is to check for the presence of a marker file,
possibly hidden.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 11 Feb 2006 03:03 GMT
>Is there any way to get the volume label name in java of a certain
>drive.  This would be for a program that I would run in Windows XP.  Of
>if anyone has a suggestion of a better way to do this, I am wanting to
>find out if a certain usb drive is plugged into the computer.  I just
>figured that the best way to test it would be to check the label,
>because the label shouldn't be changing.  

This is a platform specific notion, so you need JNI to do this. Figure
out how to do it in C and write some JNI glue.  I will write it for
you for $50 US, Windows only, but of course extensible to other
platforms by writing more C code.

Other possibilities: look at some of the JNI libraries I link to at
http://mindprod.com/jgloss/jni.html   Some may already have the
feature.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Chris Smith - 11 Feb 2006 04:04 GMT
> Is there any way to get the volume label name in java of a certain
> drive.

Not precisely.  However, you can get the somewhat vaguer concept of the
"system display name" of a drive.  There is no specification
guaranteeing what that is, but in practice, on Windows XP, it turns out
to be the volume label, followed by the drive letter in parentheses.  
Good enough?

public class Test
{
   public static void main(String[] args)
   {
       FileSystemView v = FileSystemView.getFileSystemView();
       for (File f : File.listRoots())
       {
           System.out.println(v.getSystemDisplayName(f));
       }
   }
}

Although javax.swing.filechooserFileSystemView is in the Swing package,
this use of it does not depend on any other GUI concepts.  It just
happens to be that the class was placed in a Swing package mainly for
the historical reason that the people writing Swing were the first
within Sun to actually need the information that the class provides.

I've also done something odd above; normally, when you're using
FileSystemView, you'd use v.getRoots() instead of File.listRoots().  
However, v.getRoots() shows the "logical" roots that should be shown to
a user, and that's "Desktop" on Windows, rather than any real filesystem
roots.  If you navigated with FileSystemView, you'd have to manually
follow the path through "My Computer" to the drive, and that would
involve more OS-specific code than is really necessary.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



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.