1. It is more common to read the properties file under the project root path.
The specific code is as follows:
package Com.xuanen.util;import Java.util.properties;import Org.springframework.core.io.classpathresource;import org.springframework.core.io.support.PropertiesLoaderUtils; public class Propertyutil {private static Properties propertie;private static Logger Logger = Logger.getlogger (Propertyut Il.class);/** * Read configuration file */public static Properties init () {if (Propertie = = null) {Propertie = new Properties (); try {propertie = propertiesloaderutils.loadproperties (New Classpathresource ("Common.properties" )); } catch (Exception ex) {Logger.error (Ex.getmessage ()); }} return propertie; }/** * Get SOLR config path */public static String Getdateconfigxmlpath () {propertie = init (); String Path = Propertie.getproperty ("Dateconfigpath"); return path; }}
2. It is uncommon to read properties files anywhere on the disk, but also to master them. The code is as follows
public class getsolrcreatedate{ //Get configuration file for Dataimport.properties index creation time
Here you can replace the properties file location anywhere in the disk for example: e:/dataimport.properties
private static String Path = Propertyutil.getdateconfigxmlpath (). Replace ("Data-config.xml", "") + "Dataimport.properti Es "; private static Properties Propertie; private static Logger Logger = Logger.getlogger (Propertyutil.class); /** * Read Config file */public static Properties init () {if (Propertie = = null) {Properti E = new Properties (); try {if (Fileutils.isexcite (path)) {Propertie = PROPERTIESLOADERUTILS.LOADPR Operties (new Pathresource (path)); }} catch (Exception ex) {Logger.error (Ex.getmessage ()); }} return propertie; }//Get index changed by table name public static string Getcreatedatebytablename (String tableName) {Propertie = init ( ); String data = Propertie.getproperty (tablename+ ". Last_index_time"); if (Stringutils.isnotblank (data)) {RetuRN data; } return null; }}
Java reads the properties file under the project root path and any disk location