-3

URL url=new URL("http://www.google.com/stackoverflow/question");

OUPUT

path1=stackoverflow, path2=question,

ANOTHER

URL url=new URL("http://www.google.com/stackoverflow/question/java");

OUTPUT

path1=question path2=java

If we enter dynamic url than how we can find the paths like this. Thanks

1 Answers1

0

please try the code below -

public static void main(String[] args) throws Exception {

   URL aURL = new URL("http://www.google.com/stackoverflow/question");
    String[] pathSplit = aURL.getPath().split("/");
    System.out.println("path1 = " + pathSplit[1]);
    System.out.println("path2 = " + pathSplit[2]);
}
Bheem Singh
  • 607
  • 7
  • 13