Get the files in the src directory (no src directory) in Web programming

Source: Internet
Author: User

This situation will meet more, like a Web project, if you write an XML or some other file under SRC, when the project is published to the server, the Web program is running the program under the Tomcat and other servers, this time, the program directory does not have the SRC folder, So what do we do in this situation?

In fact, when the program is published to the server, SRC files will also be published together to the server, but there is no src directory, in this case, can be obtained by the following code:

/** * The location of the data file */private static String dbfilepath= "";/** * Gets the location of the data file because the file is running in Tomcat and there is no SRC folder, so this is the way to do it * The DOM4JUTISL inside refers to the current class */static {ClassLoader cl =  Dom4JUtils.class.getClassLoader (); URL url = cl.getresource ("Users.xml");d Bfilepath = Url.getpath ();//Here is the real directory, the server can not have a Chinese directory, otherwise ....}

  

When this project was created, there was an XML file, and it was necessary to get the path to the file using the method above.

Get the files in the src directory (no src directory) in Web programming

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.