Idea读取不到properties文件

本文介绍了在IntelliJ IDEA(Idea)中遇到读取properties文件问题的解决方案,重点是检查并修改项目的pom.xml配置。
摘要由CSDN通过智能技术生成

修改pom.xml文件

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
              
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Java中,可以使用Properties类来读取和处理配置文件。以下是一个示例代码,演示如何在IDEA中使用软引用外部配置文件,并在配置文件存在时优先使用外部配置。 假设我们有一个名为config.properties的配置文件,内容如下: ``` key1=value1 key2=value2 ``` 现在,我们将在Java代码中读取和使用此配置文件。首先,确保将config.properties文件放在项目的根目录下。 ```java import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class Main { public static void main(String[] args) { Properties properties = new Properties(); // 尝试从外部文件加载配置 try { FileInputStream externalConfig = new FileInputStream("config.properties"); properties.load(externalConfig); externalConfig.close(); System.out.println("Loaded external config file."); } catch (IOException e) { System.out.println("External config file not found. Using default values."); } // 获取配置值 String value1 = properties.getProperty("key1", "default1"); String value2 = properties.getProperty("key2", "default2"); // 使用配置值 System.out.println("Value 1: " + value1); System.out.println("Value 2: " + value2); } } ``` 上述代码首先尝试从外部文件加载配置。如果到外部文件,则加载其中的值。如果不到外部文件,则使用默认值。 请确保将config.properties文件放在正确的位置,并根据需要进行相应的更改。 希望对你有所帮助!如有任何其他问题,请随时提出。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值