user3650408 user3650408 - 1 year ago 125
Java Question

URL parse without String split

Java has cool URL parser


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

URL aURL = new URL(""
+ "/index.html?name=networking#DOWNLOADING");

System.out.println("path = " + aURL.getPath());

Here is the output displayed by the program:

path = /docs/books/tutorial/index.html

I would like to take only this part :
) Guessing don`t use string split, I am looking for other better resolution for this task.

Thank you in advance

Answer Source
String path = "/docs/books/tutorial/index.html";
path = path.substring(1, path.lastIndexOf("/"));

gives docs/books/tutorial

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download