1.  Create tool class  
package com.ljw.util; import java.io.IOException; import java.io.InputStream;
import java.util.Properties; /** * Properties Profile operation class * */ public class
PropertiesUtil { /** * obtain Properties Object by address * @param propertiesPath Properties
address * @return Properties object */ public static Properties getProperties(String
propertiesPath){ try{ Properties properties = new Properties(); //
use ClassLoader load properties The configuration file generates the corresponding input stream InputStream in =
PropertiesUtil.class.getClassLoader().getResourceAsStream(propertiesPath); //
use properties Object loading input stream properties.load(in); return properties; }catch (Exception
e) { e.printStackTrace(); } return null; } /** * obtain Properties in Key Value of *
@param propertiesPath Properties address * @param key key * @return corresponding key Value of */ public
static String getPropertiesOnKey(String propertiesPath , String key){ try{
Properties properties = getProperties(propertiesPath); return
properties.getProperty(key); }catch (Exception e) { e.printStackTrace(); }
return null; } /** * write in properties information * @param propertiesPath Properties address address
( stay resources or java Under the root directory example :jdbc.properties) * @param maps Key value list * @author wlj */
public static void writeProperties(String propertiesPath, Map<String, String>
maps) { Properties prop = new Properties(); try { propertiesPath =
PropertiesUtil.class.getClassLoader().getResource("").getPath() +
propertiesPath; InputStream fis = new FileInputStream(propertiesPath);
prop.load(fis); OutputStream fos = new FileOutputStream(propertiesPath); for
(String key : maps.keySet()) { prop.setProperty(key, maps.get(key)); }
prop.store(fos, "updated"); } catch (IOException e) { e.printStackTrace(); } } }
2.  call
// obtain src lower ftp.properties Properties ftp = getProperties("ftp.properties");
// return Properties object System.out.println(ftp.getProperty("ftpHost")); // get attribute
System.out.println(ftp.getProperty("ftpUserName"));
System.out.println(ftp.getProperty("ftpPassword"));
System.out.println(ftp.getProperty("ftpPort")); // obtain config.pa Package
pa.properties Properties pa = getProperties("config/pa/pa.properties");
System.out.println(pa.getProperty("username")); // get attribute // obtain config.test Package
pa.properties Properties test = getProperties("cfg/test/test.properties");
System.out.println(test.getProperty("host")); // get attribute // obtain src lower
ftp.properties Document's ftpHost attribute
System.out.println(PropertiesUtil.getPropertiesOnKey("ftp.properties",
"ftpHost")); // Returns the corresponding value // obtain config.pa Package pa.properties Document's username attribute
System.out.println(PropertiesUtil.getPropertiesOnKey("config/pa/pa.properties",
"username")); // obtain config.test Package test.properties Document's host attribute
System.out.println(PropertiesUtil.getPropertiesOnKey("config/test/test.properties",
"host")); // write in src lower ftp.properties Map<String, String> maps = new
HashMap<String, String>(); maps.put("ftpUserName", "sa");
maps.put("ftpPassword", "123");
PropertiesUtil.writeProperties("ftp.properties", maps);
3. properties File path map

Technology