How to create a maven project idea to create properties in the properties file it

When we use JDBC or some other way to access external resources, the need to read some additional configuration file
example xml or properties, we have to regulate the location of the files created.
Here Insert Picture Description
Fill in the file name directly
Here Insert Picture Description
thus creating a property file jdbc.properties of.
And then take the test can be used to access the Java

    @Test
    public void test3(){
        Properties p=new Properties();
        InputStream is=Test1.class.getClassLoader().getResourceAsStream("jdbc.properties");
        try {
            p.load(is);
            System.out.println(p.get("user"));
            System.out.println(p.get("pwd"));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
user=zhang
pwd=abc123

operation result
Here Insert Picture Description

Published 109 original articles · won praise 56 · views 5686

Guess you like

Origin blog.csdn.net/zhang6132326/article/details/104868975