You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PAIR/src/main/java/com/pair/util/AppDataDirectory.java

43 lines
1.4 KiB

package com.pair.util;
/**
* 应用数据目录管理器
* 根据不同操作系统返回合适的应用数据存储路径
*/
public class AppDataDirectory {
private static final String APP_NAME = "Math-Quiz-App"; // 替换为你的应用名
/**
* 获取应用数据根目录
*/
public static String getApplicationDataDirectory() {
String os = System.getProperty("os.name").toLowerCase();
String basePath;
if (os.contains("win")) {
// Windows
String appData = System.getenv("APPDATA");
basePath = (appData != null) ? appData : System.getProperty("user.home") + "/AppData/Roaming";
} else if (os.contains("mac")) {
// macOS
basePath = System.getProperty("user.home") + "/Library/Application Support";
} else {
// Linux/Unix
String xdgDataHome = System.getenv("XDG_DATA_HOME");
if (xdgDataHome == null) {
xdgDataHome = System.getProperty("user.home") + "/.local/share";
}
basePath = xdgDataHome;
}
return basePath + "/" + APP_NAME;
}
/**
* 获取完整的应用数据路径
*/
public static String getFullPath(String relativePath) {
String appDataDir = getApplicationDataDirectory();
return appDataDir + "/" + relativePath;
}
}