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)?

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)?
ionutcibAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
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
 
for_yanCommented:
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
 
for_yanCommented:
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
 
CEHJCommented:
:)

>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.