导入
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
代码
String path=" 文件路径及名称,例:D://test.txt";
if(Desktop.isDesktopSupported()&&Desktop.getDesktop().isSupported(Desktop.Action.OPEN)){
File file = new File(path);
if(file.exists()){
try {
Desktop.getDesktop().open(file);
//打开成功
} catch (Exception e) {
//打开打开失败
}
}else{
//无文件"
}
}