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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:45:05+00:00 2026-06-16T00:45:05+00:00

I have a section of code that is supposed to check if an mp3

  • 0

I have a section of code that is supposed to check if an mp3 file is stored in the SD card on the MediaStore.Audio.Media content provider

the problem is that no matter the situation. Either if the file with the pathname stored in variable “audioFilename” exists on the SD card or not. it always returns “this file does not exist” as the result. Despite the fact that the variable audioFilename has the String path name stored in it “/mnt/sdCard/Music/Jungle.mp3”, and this MP3 file is actually on the SD card. Easy to prove with a Toast message and a check of the SD card contents.

I probably have an error in the use of File or Environment classes. Can anyone see a problem in the code shown here?

 // toast message to prove that the audioFilename is not null,
 // message displayed is the string, "File name: /mnt/sdCard/Music/Jungle.mp3"

 Toast.makeText(Editor.this, "File name: " + audioFilename,
 Toast.LENGTH_LONG).show();

 // the code below always returns "this file does not exist"

 File extStore = Environment.getExternalStorageDirectory();
 File myFile = new File(extStore.getAbsolutePath() + "audioFilename");

 if(myFile.exists()){

 Toast.makeText(Editor.this, "<<<< this file exists, it is: "+audioFilename+" >>>>",
 Toast.LENGTH_LONG).show();

 } else if(!myFile.exists()){

 Toast.makeText(Editor.this, "<<<< this file does not exist >>>> ",
 Toast.LENGTH_LONG).show();
 }

 Toast.makeText(Editor.this, "audio file name is: "+ audioFilename,
 Toast.LENGTH_LONG).show();
  • 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-16T00:45:06+00:00Added an answer on June 16, 2026 at 12:45 am

    Try to change this line

    File myFile = new File(extStore.getAbsolutePath() + "audioFilename");
    

    with

    File myFile = new File(audioFilename);
    

    I have run test with the same code and it is working well.

    Here is the code I test with :

    String audioFilename =  "/sdcard/NewFolder/test1.jpg";
    
    Toast.makeText(SimpleTest.this, "File name: " + audioFilename,
    Toast.LENGTH_LONG).show();
    
    // the code below always returns "this file does not exist"
    
    File extStore = Environment.getExternalStorageDirectory();
    File myFile = new File(audioFilename);
    
    if(myFile.exists()){
    
        Toast.makeText(SimpleTest.this, "<<<< this file exists, it is: "+audioFilename+" >>>>",
        Toast.LENGTH_LONG).show();
    
    } else if(!myFile.exists()){
    
        Toast.makeText(SimpleTest.this, "<<<< this file does not exist >>>> ",
        Toast.LENGTH_LONG).show();
    }
    
    Toast.makeText(SimpleTest.this, "audio file name is: "+ audioFilename,
    Toast.LENGTH_LONG).show();
    

    Hope it helps you.

    Thanks.

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

Sidebar

Related Questions

I have a section of code that can be summarised as follows; void MyFunc()
I have the following section of code in an app that I am writing:
first some code: I have many elements like that: <section class=item> <div class=caption> </div>
Ok. I have this little bit of code that is supposed to use text
I have this section of code: public static void delete(File f) throws IOException {
Javascript I have code that will hide various sections in a MS CRM form
I have a section of code which should be executed by a maximum number
I have this view (DetailsContainer, first class in code section of this question) with
I have some VERY simple code to return the title for a section header:
In my xaml code, inside the Window.Resources section, I have defined a Data Template

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.