> Can anyone tell me what is the best way to seperate a filename and a
> path so I'm left with 2 strings.
Intuitively I would use methods in java.lang.String to find the last
instance of the separator character, then create substrings around
that point.
However there are also methods in java.io.File that will do exactly
this for you: getName() and getParent().
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
>Hi There,
>
[quoted text clipped - 9 lines]
>String path = "/path/to/my";
>String file = "file.txt";
String fullPath = new String("/path/to/my/file.txt");
int i = fullPath.lastIndexOf("/");
String path = fullPath.substring(0, i);
String file = fullPath.substring(i + 1);
--
Tim Slattery
Slattery_T@bls.gov
Steve W. Jackson - 05 Oct 2006 18:28 GMT
> >Hi There,
> >
[quoted text clipped - 18 lines]
> Tim Slattery
> Slattery_T@bls.gov
As was pointed out in an earlier reply, there's another way that IMHO is
most definitely better than anything involving lastIndexOf since the OP
specifically shows x-plat interest. That's the use of the java.io.File
class instead.

Signature
Steve W. Jackson
Montgomery, Alabama
Noodle - 06 Oct 2006 01:25 GMT
> >Hi There,
> >
[quoted text clipped - 18 lines]
> Tim Slattery
> Slattery_T@bls.gov
Thank you everyone for your speedy reply's. I've based my code on Tim's
reply and it works well...
String fullPath = "/path/to/my/file.txt";
int i = fullPath.lastIndexOf(System.getProperty("file.separator"));
String path = fullPath.substring(0, i);
String file = fullPath.substring(i + 1);
do you mean by using String::lastIndexOf("/");
Noodle 写道:
> Hi There,
>
[quoted text clipped - 11 lines]
>
> TIA