Solved

Java - get Drive VolumeName

Posted on 2006-11-11
3
1,427 Views
Last Modified: 2011-04-14
Is it possible in Java to find the VolumeName of CD/DVD/Hard Disk?

I really want to know if this can be done purely in Java, I know I could write code to do this in C++ and use JNI, but that's not really what I'm after.

Note, I asked this question a long time ago for C# and got a perfect solution: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21409394.html

Problem is I had a hard disk crash and lost the program I wrote in C#.  Now I want to write it again but this time in Java.  I don't use .Net anymore, I don't even have .Net installed and don't really want to install it.

Can it be done?
0
Comment
Question by:basicinstinct
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 500 total points
Comment Utility
Please see if the following suits your need:

import javax.swing.filechooser.*;
import java.io.*;

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

Expert Comment

by:Peter Kwan
Comment Utility
0
 
LVL 23

Author Comment

by:basicinstinct
Comment Utility
pkwan

That is EXACTLY what I needed, and your sample code was perfect.  
Thank you, you are a scholar and a gentleman.

Top marks, grade A, well deserved.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now