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