How to open windows explorer at the user home?

Hi all,

I have a button which is supposed to open the windows explorer at the user's home.

I'm using the code:

Process p = Runtime.getRuntime().exec(path);

to open windows explorer, but I have no clue how to get the user's home folder. I'd like also to create a new subfolder into the user's home folder, if it doesn't exist.

Does anybody knows how can I do that?

[406 byte] By [Valerianoa] at [2007-11-27 3:44:20]
# 1
If you are using the current version of Java, you can use java.awt.Desktop to open the user's default browser -- Firefox, in my case, since I hate IE. http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html
DrLaszloJamfa at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...
# 2
I don't want to open internet explorer.I want to open windows explorer.
Valerianoa at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...
# 3

public class Command {

public static void main(String[] args) {

try {

Process p =

Runtime.getRuntime()

.exec("explorer "+System.getProperty("user.home"));

p.waitFor();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

java_2006a at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...
# 4

Is this what you want ?

import java.io.File;

public class Command {

public static void openDirectory(String dirPath){

try {

File file= new File(dirPath);

boolean test = true;

if(!file.exists()){

test = file.mkdirs();

}

if(test){

Process p =

Runtime.getRuntime()

.exec("explorer "+dirPath);

p.waitFor();

}

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

Command.openDirectory(System.getProperty("user.home")+"\\myfolder");

}

}

Hope That Helps

java_2006a at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...
# 5
> I don't want to open internet explorer.> I want to open windows explorer.Woops. Sorry, read too fast.
DrLaszloJamfa at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...
# 6
...of course, no thanks !!
java_2006a at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...
# 7
Thanks a lot java_2006.That's exactly what I wanted.
Valerianoa at 2007-7-12 8:47:59 > top of Java-index,Java Essentials,New To Java...