Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:08:42+00:00 2026-05-30T23:08:42+00:00

I want to get the file extension in my Java code: File f =

  • 0

I want to get the file extension in my Java code:

File f = new File(....);
String name = f.getName();
int pos = name.lastIndexOf('.');
String ext = name.substring(pos+1);

I tried this code but it didn’t work in OS X Lion, in Windows it works.

UPDATE
for example
i have a png file in my desktop with this name Screen Shot 2012-02-23 at 1.26.27 PM
i get the 27 PM extension with this code .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:08:44+00:00Added an answer on May 30, 2026 at 11:08 pm

    Your code is doing exactly what you’ve asked it to do. It’s finding the filename extension on the file. The problem is that you have file with a stupid name that should have a “.png” extension, but doesn’t. If you still want your code to handle this, you might need to look at interpreting the file header to determine the type of the file, which is presumably what OS X is doing to know that it is really a .png file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the file name without the file extension in Vim. I
I want to get the image file name without the Extension in MATLAB. I
I want to get the file extension of a file however the file name
I want to get path to the programs that associated with file extension, preferably
I want to get the name of the currently running batch file without the
i want get extension file of url . for example get extension http://www.iranfairco.com/download-file/02912bb889cb24 .
I want to get actual file extension from the remote url. sometimes extension not
I get an XML file From a web service. Now I want to get
I want to get the size of an http:/.../file before I download it. The
I want to get the icons of common file types in my dll. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.