Files
contract-manager/src/main/java/com/ecep/contract/manager/MyProperties.java
2025-08-22 19:55:19 +08:00

36 lines
939 B
Java

package com.ecep.contract.manager;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
@Component
@ConfigurationProperties(prefix = "my")
public class MyProperties {
@Getter
@Setter
private String downloadsPath;
/**
* 尝试返回当前用户的下载文件夹
*/
public File getDownloadDirectory() {
String downloadsPath = getDownloadsPath();
if (StringUtils.hasText(downloadsPath)) {
return new File(downloadsPath);
}
// 没有配置下载目录时,尝试使用默认设置
String home = System.getProperty("user.home");
Path path = Paths.get(home, "Downloads");
return path.toFile();
}
}