'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. Advertising

  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. Advertising

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:
    503
    Joe Smith
    Apr 14, 2004
  2. Xah Lee
    Replies:
    14
    Views:
    968
    Michele Dondi
    Jan 27, 2004
  3. Devon Null

    Am I re-inventing the wheel?

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

    Plattform independent basename function

    Markus Litz, Jan 21, 2009, in forum: C Programming
    Replies:
    19
    Views:
    5,821
    jameskuyper
    Jan 22, 2009
  5. Justin C
    Replies:
    6
    Views:
    131
    Justin C
    Apr 24, 2007
Loading...

Share This Page