The code is as follows:
Locate the Tomcat/etc/wx folder private static String Getpropfolderpath () {/* Properties p =system.getproperties();P.list (System.out); * *Get the path to tomcat String path =System.getproperty("Catalina.home"); if (stringutils.isempty (path)) {path = QueryQRCodeUrlController.class.getResource ("/"). GetPath (); Path = new File (path). GetParent () + file.separator; } else {path = path +File.separator+ Tomcat_path; } return path; }Initializing configuration information ************************static{Properties P=new properties ();InputStream In=null;try {In=new FileInputStream (Getpropfolderpath () +wx_properties);P.load (in);VALUE = P.getproperty ("Wx.serviceid");PWD = P.getproperty ("Wx.pwd");} catch (Exception e) {Logger.error (E.tostring ());}finally{if (in!=null) {try {In.close ();} catch (IOException e) {Logger.error (E.tostring ());}}}}
1:file.separator the system-related default name delimiter.
The path separators under windows are not the same as the path separators under Linux, and when you use absolute paths directly, cross-platform bursts out "No such file or diretory" exceptions.
For example, to create a test.txt file under the temp directory, which should be written under Windows:
File File1 = new file ("C:\tmp\test.txt");
Under Linux, this is the case:
File File2 = new file ("/tmp/test.txt");
If you want to consider cross-platform, it's best to write this:
File MyFile = new file ("C:" + file.separator + "tmp" + file.separator, "test.txt");
The file class has several static fields similar to separator, which are system-related and should be used as much as possible when programming.
2:system.getproperties (): This method is to get many property names and value values for the current system. After these key-value pairs are obtained, the value values can be obtained in the following ways:
System.getproperty ("Catalina.home"); If you know these properties of the system, you can obtain the corresponding value value directly from this method.
3: Static code block:
static{
System.out.println ();
}
Used to initialize some information, and after the service is started, the class is executed when it is loaded. Executes only once.
Java program reads the properties configuration file under Tomcat