Java path Retrieval Methods

Source: Internet
Author: User
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

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.