package com.shucha.deveiface.biz.utils;
import com.sdy.common.utils.StringUtil;
/**
* @author tqf
* @Description 判断当前系统类型 Linux还是Windows
* @Version 1.0
* @since 2022-04-12 11:34
*/
public class OsPathUtil {
public static String convertToUnix(String path) {
if (StringUtil.isBlank(path)) {
return path;
}
if (path.startsWith("e:/") || path.startsWith("E:/")) {
path = path.substring(2);
}
return path;
}
public static String convertToWindows(String path) {
if (StringUtil.isBlank(path)) {
return path;
}
if (!(path.startsWith("e:/") || path.startsWith("E:/"))) {
path = "E:".concat(path);
}
return path;
}
public static String convertWithOs(String path) {
if (StringUtil.isBlank(path)) {
return path;
}
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
return convertToWindows(path);
} else {
return convertToUnix(path);
}
}
public static void main(String[] args) {
System.out.println(convertWithOs("opt/file"));
}
}