Summarize several methods for obtaining paths in Java --
When writing Java
ProgramIt is inevitable to obtain the file path... to sum up, add the missing items at any time. in the init method of servlet, string Path = getservletcontext (). getrealpath ("/"); this will obtain the full path of the web project, for example, E:/eclipsem9/workspace/tree/is the root directory of my web project 2. you can also call this in any class at any time. getclass (). getclassloader (). getresource ("/"). getpath (); this will get the full path of the classes directory, for example: e:/eclipsem9/workspace/tree/WEB-INF/classes/this method can also not determine the path in the web environment, relatively easy to use 3. request. getcontextpath (); obtain the context of the web root. For example,/treetree is the root Co of my web project. Ntext from: http://publishblog.blogchina.com/blog/tb. B? Diaryid = 1709567