[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to detect system drive using JAVA

Posted on 2009-12-25
6
Medium Priority
?
1,215 Views
Last Modified: 2013-12-14
As the topic says.I need short function to detect system drive letter.
0
Comment
Question by:Maranellas
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ioanton
ID: 26123103
You can use:

File[] roots = File.listRoots();

to get the list of drives on your system
0
 

Author Comment

by:Maranellas
ID: 26123384
I don't need to get list of drives.I need to get main drive where windows installed.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26123901
try the following code

String systemDrive = System.getProperty("SystemDrive");

see the following link for reference
http://www.bigresource.com/Tracker/Track-vb-NkqegKV5n3/
http://leepoint.net/notes-java/io/30properties_and_preferences/40sysprops/10sysprop.html
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:ioanton
ID: 26123916
Another approach:

System.out.println(System.getProperty("user.home").charAt(0));

Assuming the user home directory is always an the windows drive.
0
 

Author Comment

by:Maranellas
ID: 26124471
okay when i try

String systemDrive = System.getProperty("SystemDrive");

i get NULL response

and when i try System.out.println(System.getProperty("user.home").charAt(0));

i get the following error

found   : char
required: java.lang.String
        private String drv = System.getProperty("user.home").charAt(0);

but java.lang package is imported already
0
 
LVL 9

Accepted Solution

by:
ioanton earned 2000 total points
ID: 26124484
Indeed, the returned value is of type char. But you can convert it to string using:

Character.toString(System.getProperty("user.home").charAt(0));
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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