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]

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
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();
}
}
}
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