Edited Question:
try{
folder=jTextField1.getText()+"_portfolio";
String path="E:/test folder/"+folder+"";
Desktop.getDesktop().open(path);
}catch(Exception E){
}
I got error method open in class java.awt.Desktop cannot be applied to given types.
See Desktop.open(File)
. E.G.
Desktop.getDesktop().open(theDirectory);
import java.awt.Desktop;
import java.io.*;
public class BrowseDirectory {
public static void main(String[] args) throws IOException {
String userHomePath = System.getProperty("user.home");
File userHome = new File(userHomePath);
Desktop.getDesktop().open(userHome);
}
}
Although the directory appears as "My Videos" to the end user, forming a file inside the directory and checking the properties of the file, reveals the underlying name is "Videos".
import java.awt.Desktop;
import java.io.*;
public class BrowseDirectory {
public static void main(String[] args) throws IOException {
String userHomePath = System.getProperty("user.home");
File userHome = new File(userHomePath);
// uses the corect path separator for the OS
File videos = new File(userHome, "Videos");
Desktop.getDesktop().open(videos);
}
}
try {
String path = "C:\\path\\of\\your\\folder\\";
Runtime runtime = Runtime.getRuntime();
runtime.exec("explorer.exe "+path);
System.out.println("open");
} catch (Exception E) {
}
you can use any path that you want but convert it 1st to string and please be aware in java "\" should written "\\"
hope it works :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With