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

Discussion in 'Java' started by Ronald Fischer, Jul 22, 2003.

  1. 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
     
    Ronald Fischer, Jul 22, 2003
    #1
    1. Advertisements

  2. Ronald Fischer

    Jacob Guest

    Ronald Fischer wrote:
    > 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();
     
    Jacob, Jul 22, 2003
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Berry

    Confused on using basename...

    Sean Berry, Apr 14, 2004, in forum: Perl
    Replies:
    1
    Views:
    665
    Joe Smith
    Apr 14, 2004
  2. Xah Lee
    Replies:
    14
    Views:
    1,145
    Michele Dondi
    Jan 27, 2004
  3. Peter Saffrey

    basename with extensions

    Peter Saffrey, Aug 30, 2006, in forum: Python
    Replies:
    1
    Views:
    3,378
    Tal Einat
    Aug 30, 2006
  4. basename in C++

    , Oct 5, 2006, in forum: C++
    Replies:
    4
    Views:
    17,535
    Jens Theisen
    Oct 5, 2006
  5. Thomas Ploch
    Replies:
    2
    Views:
    749
    Thomas Ploch
    Mar 14, 2007
  6. Devon Null

    Am I re-inventing the wheel?

    Devon Null, Jun 6, 2007, in forum: C++
    Replies:
    4
    Views:
    459
    Devon Null
    Jun 7, 2007
  7. Markus Litz

    Plattform independent basename function

    Markus Litz, Jan 21, 2009, in forum: C Programming
    Replies:
    19
    Views:
    7,049
    jameskuyper
    Jan 22, 2009
  8. Justin C
    Replies:
    6
    Views:
    270
    Justin C
    Apr 24, 2007
Loading...