java打開文件夾操作!(轉)

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 " );
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章