Use xml configuration file storage information in the project

Source: Internet
Author: User

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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.