package testReadFile;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.IOException;
import java.util.Properties;
public class LoadAbsolutePathConfig {
public static void main(String[] args) {
// 配置文件的绝对路径
String absolutePath = "D:\\java\\test\\auto\\logs\\loginParam.properties";
// 创建一个 FileSystemResource 对象
Resource resource = new FileSystemResource(absolutePath);
try {
// 加载配置文件
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
// 输出读取到的配置项
properties.forEach((key, value) -> System.out.println(key + " : " + value));
} catch (IOException e) {
e.printStackTrace();
}
}
}