java打开文件夹操作!

luozhangwen 2010-04-26 04:52:19

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

...全文
620 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangzztt 2012-05-03
  • 打赏
  • 举报
回复
正好学习下 。。。。。

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧