36 lines
939 B
Java
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();
|
|
}
|
|
}
|