Absolute and relative paths to "Java"

Source: Internet
Author: User

Here is the directory path to differentiate
Such as:

/opt/deve/tomcat/bin
C:\deve\tomcat\bin
are absolute directory paths

Bin
Bin/data
Bin\data
are relative directory paths

by observing, discovering the law

Either start or include \ or//are absolute paths or
To/start or include: absolute path
The opposite is the relative path.

Introduce several methods:


    1. StartsWith

    2. public class Stringutil {

    3. public static void Main (string[] args) {

    4. String Path = "/opt/bin";

    5. System.out.println (Path.startswith ("/"));

    6. }

    7. }


    8. Result: True


    9. IndexOf

Copy Code


Final Result:



    1. public boolean Isabsolutepath (String path) {

    2. if (Path.startswith ("/") | | path.indexof (":") > 0) {

    3. return true;

    4. }

    5. return false;

    6. }

More Java,java learning, Java face Test http://techfoxbbs.com


Absolute and relative paths to "Java"

Related Article

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.