?
Solved

Returning the path to "My Documents" directory on Windows Platform

Posted on 2004-11-10
6
Medium Priority
?
269 Views
Last Modified: 2008-03-10
In Java is it possible to get the location (path) of the "My Documents" directory in Java. This directory has the ability of being located somewhere other than it's default on C:\. For instance it can be set to be located on a corporate IT drive for auto backup purposes. So whatever function I use needs to report back the absolute path to the "My Documents" actual location. A code snippet is not necessary if you can point me to the documentation to accomplish this. Thanks.
0
Comment
Question by:tk1016
6 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12548804
try this:

String userHome = System.getProperty(:user.home");

//or user.dir please try both
0
 
LVL 13

Assisted Solution

by:petmagdy
petmagdy earned 450 total points
ID: 12548810
sorry offcourse:
String userHome = System.getProperty("user.home");
0
 
LVL 4

Assisted Solution

by:gdrnec
gdrnec earned 450 total points
ID: 12548814
System.getProperty("user.home");

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
TrekkyLeaper earned 600 total points
ID: 12548821
I know this works in NT-based systems for the default location, so hopefully this will give you an idea. There is a "java.home" environment variable (retrievable from System.getProperty( "java.home" )) that will point to the user's base directory. That would be c:\documents and settings\<username> in NT-based systems.

I think your best option in this case would be to pass the path to the "My Documents" directory in on the commandline:

java -Duser.document.dir="drive:\path\My Documents" my.package.MyClass

Then, you would be able retrieve it using System.getProperty( "user.document.dir" ).

I know this isn't the sure-fire answer you wanted, but I hope it will at least give you an idea.
0
 
LVL 5

Expert Comment

by:TrekkyLeaper
ID: 12548824
Yeah. Everyone else is right. "user.home" not "java.home".
0
 

Author Comment

by:tk1016
ID: 12701438
Hi all,

thanks for answering...none of the above actually return the path to where "My Documents" is located if the system option to move that directory is exercised. The system can find it, but java still cannot. Another team member ended up doing some JNI so we could call the Windows Function directly.

Thanks...I have other questions though.
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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 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