Some system-level configuration information is often used in projects. In this case, the writing information is stored in what way and read in what way. Here is a brief discussion of how to store xml files.
Recently, projects require that you write the same file upload path and provide modifiable configuration interfaces. Here, I use the xml file configuration method. The Code is as follows:
Configuration file:
Java code:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Config>
<! -- File Upload path -->
<Upload_path>/tmp/</upload_path>
</Config>
Util class for configuration file read/write:
Java code: www.2cto.com
Public class Config {
// Parse the config. xml configuration file and return the file storage path
Public String getUploadPath () throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory. newInstance ();
DocumentBuilder builder = factory. newDocumentBuilder ();
String configPath = this. getClass (). getResource ("/"). getPath () + File. separator + "config. xml ";
Document document = builder. parse (configPath );
NodeList nodeList = document. getElementsByTagName ("upload_path ");
Node node = nodeList. item (0 );
Return node. getTextContent ();
}
}