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 " );
}
}
java打开文件夹操作!(转)
最新推荐文章于 2024-11-13 15:26:14 发布
本文提供了一个使用Java实现打开指定文件夹路径的例子。通过检测操作系统类型,选择使用Windows的Explorer或Unix/Linux下的Netscape来浏览文件夹。适用于希望在不同操作系统上保持一致文件夹浏览体验的开发者。
2616

被折叠的 条评论
为什么被折叠?



