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 8230845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:16:10+00:00 2026-06-07T17:16:10+00:00

i get mime type of a file using the following code: private String getMimeType(String

  • 0

i get mime type of a file using the following code:

    private String getMimeType(String url) {

        String type = null;
        String extension = MimeTypeMap.getFileExtensionFromUrl(url);
        Log.e("extension ", extension);

        if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
        }
        return type;
    }

   where url is the absolute file path

    i am getting file and folder by the following way
    File file_arr [];
    file_arr = new   File(Environment.getExternalStorageDirectory().getPath()).listFiles();
    url = file_arr[i].getAbsolutePath();

this is working correct but it return always null for which file has dot ” . “ in its file name.

for the example

if the file name is picture1.jpg then the getMimeType() return image/jpeg

in the case of file name has dot (.) in its name for the example 27-05-2012 22.05.14.jpg then the getMimeType() return null.

i have renamed the file to 27-05-2012.jpg, its return image/jpeg.

my question how to get mime type for all types of file name(which is has dot or special character) on android? please help me.

  • 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-06-07T17:16:11+00:00Added an answer on June 7, 2026 at 5:16 pm

    How about this:

    File f = new File(file);
    System.out.println(new MimetypesFileTypeMap().getContentType(f));
    

    Or

       if(url.lastIndexOf(".") != -1) {
        String ext = url.substring(url.lastIndexOf(".")+1);
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        String type = mime.getMimeTypeFromExtension(ext);
       } else {
        String type = null;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get a file's MIME type using some system call
I'm trying to get the MIME type of an <input type=file /> element using
In my Rails app I'm trying to get the MIME type of a file
I want to get a MIME Content-Type from a given extension (preferably without accessing
I have the following code to get the album cover of an mp3 using
I want to get the MIME type from a filename using C. Is there
I am writing a small script to upload and detect MIME type, using Zend
I am using the following code, upload.php, to try to have someone upload a
I am using MIME multipart for uploading images to server. Sometime image get distorted.
Curious what the best way is in Java to get the mime-type of a

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.