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 <coomar....@gmail.com> 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 <pedroteixeir...@gmail.com> 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 <jeremy.wads...@gmail.com> 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
> > >> <pedroteixeir...@gmail.com>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) <cor...@gmail.com>
>
> > >>>> 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 
> > >>>> android-developers@googlegroups.com
> > >>>> To unsubscribe from this group, send email to
> > >>>> android-developers+unsubscr...@googlegroups.com<android-developers
> > >>>> %2bunsubscr...@googlegroups.com>
> > >>>> 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 android-developers@googlegroups.com
> > >>> To unsubscribe from this group, send email to
> > >>> android-developers+unsubscr...@googlegroups.com
> > >>> 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 android-developers@googlegroups.com
> > >>> To unsubscribe from this group, send email to
> > >>> android-developers+unsubscr...@googlegroups.com<android-developers
> > >>> %2bunsubscr...@googlegroups.com>
> > >>> 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 android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to