java打开文件夹操作!(转)
来源:互联网 发布:新顶级域名注册 编辑:程序博客网 时间:2024/05/03 22:44
package com.lzw.test;
public class OpenFolder {
public static void browsePath(String strPath) {
String[] execString = new String[2];
String filePath = null;
String osName = System.getProperty("os.name");
if (osName.toLowerCase().startsWith("windows")) {
// Window System;
execString[0] = "explorer";
try {
filePath = strPath.replace("/", "//");
} catch (Exception ex) {
filePath = strPath;
}
} else {
// Unix or Linux;
execString[0] = "netscape";
filePath = strPath;
}
execString[1] = filePath;
try {
Runtime.getRuntime().exec(execString);
} catch (Exception ex) {
System.out.println("异常啦...");
}
}
public static void main(String[] args) {
OpenFolder.browsePath("E://tools");
}
}