Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING: File.mkdir() is ignored

I've created a basic Audio Recording App using Media Recorder API's. I'm trying to create a folder in the SD card and to save my recorded files to that folder. I'm getting this warning with following code.

File.mkdir() is ignored

    // Assign random number to avoid audio file from overwriting
    Long tsLong = System.currentTimeMillis()/1000;

    // Specify a Location for the recorded file to be stored in the SD card
    mFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AudioRecordTest/";
    File path = new File(mFileName);
    if(!path.exists()) {
        path.mkdir();
    }
    mFileName += "/AudioRecordTest_" + tsLong.toString() + ".mp3";

How to solve this warning message. Feel free to modify the code if there is any other mistake.

like image 779
Srikar Reddy Avatar asked Jan 12 '15 14:01

Srikar Reddy


1 Answers

Correct me if I'm wrong, but I expect that the (compilation) warning message really says this:

Result of File.mkdir() is ignored

... or something like that. It is telling you that you are ignoring the result of the mkdir() call that tells you whether or not a directory was created.

One way to avoid the warning would be to test the result and act appropriately. Another would be to simply assign the result to a temporary variable, ignore it, and (potentially) crash later because the directory wasn't created when it should have been.

(Guess which solution is better ...)


Feel free to modify the code if there is any other mistake.

Since you asked ... it is BAD STYLE to use Hungarian notation for Java variable names. Java is a strongly typed language where all variables have a clear declared types. You should not need the mental crutches of some ghastly identifier convention to tell you what a variable's type is intended to be.

like image 186
Stephen C Avatar answered Oct 13 '22 04:10

Stephen C