'basename' function (without re-inventing the wheel)

R

Ronald Fischer

Does someone know if there is in the JDK something like the 'basename' function
from Unix or C, i.e. a function which takes a path such as

foo/bar/baz

and returns the filename, i.e.

baz.

Of course it is easy to implement this, but I don't want to re-invent the wheel,
if such a function is already available.

Ronald
 
J

Jacob

Ronald said:
Does someone know if there is in the JDK something like the 'basename' function
from Unix or C, i.e. a function which takes a path such as

foo/bar/baz

and returns the filename, i.e.

baz.

Of course it is easy to implement this, but I don't want to re-invent the wheel,
if such a function is already available.

Ronald

The function is available in java.io.File:

String name = (new File("foo/bar/baz")).getName();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top