Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I find from a Java application which is the name of Windows directory (default it is c:\windows...but it can be different)?

Posted on 2011-09-26
4
Medium Priority
?
218 Views
Last Modified: 2012-05-12
How can I find from a Java application which is the name of Windows directory (default it is c:\windows...but it can be different)?
0
Comment
Question by:ionutcib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 36598339
Yes, it can be different. Try the following (not guaranteed to work with every runtime)
String winDir = System.getEnv("WINDIR");

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36598879
You create a file - and then use getAbsolutePath()
This should work on all systems.
See example here

http://www.roseindia.net/java/java-get-example/get-CWD.shtml
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36599014
As you see in the above example you of course do not create any file on the actual file system so you don't comtaminatte it with extra files- you just create File object in your java code - so it is a good clean method of finding working directory on any system
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36599092
:)

>>http://www.roseindia.net/java/java-get-example/get-CWD.shtml

is something quite different, that incidentally can be got a lot more easily with
String cwd = System.getProperty("user.dir");

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

OfficeMate Freezes on login or does not load after login credentials are input.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

715 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