编辑问题:
try{
folder=jTextField1.getText()+"_portfolio";
String path="E:/test folder/"+folder+"";
Desktop.getDesktop().open(path);
}catch(Exception E){
}
我在类 java.awt.Desktop 中打开错误方法无法应用于给定类型。
最佳答案
参见 Desktop.open(File)
.例如
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);
}
}
更新
虽然该目录对最终用户显示为“我的视频”,但在该目录内形成一个文件并检查该文件的属性,显示底层名称是“视频”。
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);
}
}
关于java - 如何从我的电脑打开和查看文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14700679/