to get file path without the jar filename

Hi,I am trying to first check if the path contains jar file. If so, then I need to retrieve just the path without the jar file name.For ex: if the path is :c:\foo\foo.jar, I need to get c:\foo.Thanks in advance
[238 byte] By [bjra] at [2007-11-27 1:08:51]
# 1
You don't say exactly what this "path" is. If it's a string, then use String's lastIndexOf() and substring() methods.If it's a File (ie the name of an actual or possible resource on your file system c:\foo\foo.jar) then check out the File method getParent().
pbrockway2a at 2007-7-11 23:44:07 > top of Java-index,Java Essentials,New To Java...
# 2

> I am trying to first check if the path contains jar file. If so, then I need to retrieve just

> the path without the jar file name.

On second reading this just doesn't make sense. How can you "check the path" unless you know the path. And if you know the path there's nothing to retrieve.

Perhaps "foo.jar" is a resource as located by, say. ClassLoader's getResource() method. In that case you take the returned URL and use toURI() to obtain a URI from which a File can be constructed and used as I described before.

What are you really trying to do?

pbrockway2a at 2007-7-11 23:44:07 > top of Java-index,Java Essentials,New To Java...
# 3

Hey,

Is this what you want?

String str = new String("c:/foo/foo.jar");

int index = str.lastIndexOf('/');

System.err.println(str.substring(0, index));

Just take care of the path separator. you can use System Environment properties.

Cheers,

Satish Patil

Satish_Patila at 2007-7-11 23:44:07 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks for the response. I got it working by incorporating both the answers
bjra at 2007-7-11 23:44:07 > top of Java-index,Java Essentials,New To Java...