|
@@ -9,9 +9,9 @@ import java.io.IOException;
|
|
|
|
|
|
public class FolderUtils {
|
|
|
|
|
|
- protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+ protected static Logger logger = LoggerFactory.getLogger(FolderUtils.class);
|
|
|
|
|
|
- public String openFolder(String path) throws IOException {
|
|
|
+ public static String openFolder(String path) throws IOException {
|
|
|
String errorMsg = "";
|
|
|
// 指定要打开的文件夹路径
|
|
|
File folder = new File(path);
|
|
@@ -33,4 +33,37 @@ public class FolderUtils {
|
|
|
}
|
|
|
return errorMsg;
|
|
|
}
|
|
|
+
|
|
|
+ public static String openFolderAndSelectFile(String path) {
|
|
|
+ String errorMsg = "";
|
|
|
+ String osName = System.getProperty("os.name").toLowerCase();
|
|
|
+ System.out.println("Operating system: " + osName);
|
|
|
+ if (osName.contains("win")) {
|
|
|
+ try {
|
|
|
+ Runtime.getRuntime().exec("explorer.exe /select," + path);
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.warn("explorer error, path:{}", path, e);
|
|
|
+ errorMsg = "打开异常";
|
|
|
+ }
|
|
|
+ } else if (osName.contains("nux") || osName.contains("nix")) {
|
|
|
+ try {
|
|
|
+ Runtime.getRuntime().exec("nautilus " + path);
|
|
|
+ errorMsg = "打开异常";
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.warn("nautilus error, path:{}", path, e);
|
|
|
+ errorMsg = "打开异常";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Runtime.getRuntime().exec("dolphin --select " + path);
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.warn("dolphin error, path:{}", path, e);
|
|
|
+ errorMsg = "打开异常";
|
|
|
+ }
|
|
|
+ } else if (osName.contains("mac")) {
|
|
|
+ errorMsg = "IOS操作系统不支持";
|
|
|
+ } else {
|
|
|
+ errorMsg = "未识别到操作系统";
|
|
|
+ }
|
|
|
+ return errorMsg;
|
|
|
+ }
|
|
|
}
|