Well, you got it wrong i think :)
public static String fileExtension(File f) {
String name = f.getName();
int idx = name.lastIndexOf('.');
if (idx == -1) return null;
if (idx == name.length()-1) return new String("");
return name.substring(idx+1, name.length())); // that was what you got
wrong :)
}
public static string fileBaseName(File f) {
String name = f.getName();
int idx = name.lastIndexOf('.');
if (idx == -1) return name;
if (idx == 0) return new String("");
return name.substsring(0,idx); // that was what you got wrong :)
}
Now I hope I didn't make any mistake!
Best regards,
Filip Havlicek
2010/9/5 Bob Kerns <[email protected]>
> The Java File class does not provide an abstraction for "extension".
> It's a bit too abstract and least-common-denominator for that.
> Compared to when the File class was defined, modern filesystems are
> more consistent about not actually enforcing it as a part of the
> syntax, and about following it as a convention!
>
> // Untested, yell at me if I got it wrong.
> public static String fileExtension(File f) {
> String name = f.getName();
> int idx = name.lastIndexOf('.');
> return name.substring(0, idx);
> }
>
> public static string fileBaseName(File f) {
> String name = f.getName();
> int idx = name.lastIndexOf('.');
> return name.substsring(idx + 1);
> }
>
> On Sep 4, 5:38 pm, Kumar Bibek <[email protected]> wrote:
> > The file object you must be creating, has a few methods. Try
> > experimenting, and I am sure, you will find it out easily. Try the
> > method, file.getName() or something like that, I don't remember
> > exactly.
> >
> > -Kumar Bibekhttp://techdroid.kbeanie.com
> >
> > On Sep 4, 1:41 am, Pedro Teixeira <[email protected]> wrote:
> >
> >
> >
> > > Obviously not for me lol.. I'm sorry, I'm just a little bit newbie in
> > > this and its giving me a headache just to get a simple name and
> > > extension from the path
> >
> > > On Sep 3, 2010, at 9:15 PM, Kumar Bibek wrote:
> >
> > > > Use the file class. It's pretty straight forward.
> >
> > > > -Kumar Bibek
> > > >http://techdroid.kbeanie.com
> >
> > > > On Sep 4, 12:02 am, Jeremy Wadsack <[email protected]> wrote:
> > > >> This is basic java. It's not Android specific.
> >
> > > >> String filename = "something.ext";
> > > >> String extension = null;
> > > >> int lastDotPosition = filename.lastIndexOf('.');
> > > >> if( lastDotPosition > 0 ) {
> > > >> extension = filename.substring(lastDotPosition + 1);
> >
> > > >> }
> >
> > > >> --
> > > >> Jeremy Wadsack
> >
> > > >> On Fri, Sep 3, 2010 at 11:57 AM, Pedro Teixeira
> > > >> <[email protected]>wrote:
> >
> > > >>> And how is that done?
> > > >>> I found examples in javascript using the lastindexof ...but cant
> > > >>> find
> > > >>> anything for android java..
> >
> > > >>> On Sep 3, 2010, at 6:52 PM, Filip Havlicek wrote:
> >
> > > >>> Just select extension as string from . to the end and filename as
> > > >>> string
> > > >>> from last / to last .
> >
> > > >>> Best regards,
> > > >>> Filip Havlicek
> >
> > > >>> 2010/9/3 Maps.Huge.Info (Maps API Guru) <[email protected]>
> >
> > > >>>> Have you looked at File?
> >
> > > >>>> -John Coryat
> >
> > > >>>> --
> > > >>>> You received this message because you are subscribed to the Google
> > > >>>> Groups "Android Developers" group.
> > > >>>> To post to this group, send email to
> [email protected]
> > > >>>> To unsubscribe from this group, send email to
> > > >>>> [email protected]<android-developers%[email protected]>
> <android-developers
> > > >>>> %[email protected]>
> > > >>>> For more options, visit this group at
> > > >>>>http://groups.google.com/group/android-developers?hl=en
> >
> > > >>> --
> > > >>> You received this message because you are subscribed to the Google
> > > >>> Groups "Android Developers" group.
> > > >>> To post to this group, send email to
> [email protected]
> > > >>> To unsubscribe from this group, send email to
> > > >>> [email protected]<android-developers%[email protected]>
> > > >>> For more options, visit this group at
> > > >>>http://groups.google.com/group/android-developers?hl=en
> >
> > > >>> Pedro Teixeira
> >
> > > >>>www.pedroteixeira.org
> >
> > > >>> --
> > > >>> You received this message because you are subscribed to the Google
> > > >>> Groups "Android Developers" group.
> > > >>> To post to this group, send email to
> [email protected]
> > > >>> To unsubscribe from this group, send email to
> > > >>> [email protected]<android-developers%[email protected]>
> <android-developers
> > > >>> %[email protected]>
> > > >>> For more options, visit this group at
> > > >>>http://groups.google.com/group/android-developers?hl=en
> >
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to
> [email protected]
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<android-developers%[email protected]>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
> >
> > > Pedro Teixeira
> >
> > >www.pedroteixeira.org
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en