WARNING: File.mkdir() is ignored

file createnewfile is ignored
result of file delete is ignored
exceptional return value of java io file mkdirs ignored
result of inputstream read is ignored
android mkdirs not working
suppress warning result is ignored
result of tostring is ignored java

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.

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.

Result of 'File.mkdirs()' is ignored, mkdirs() is ignored. I try to fix this Warning but I failed. private void saveGIF()  that the (compilation) warning message really says this: Result of File.mkdir() is ignored. 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.

As @Stephen C suggests, i handled in these ways

1)

boolean isDirectoryCreated= path.mkdir();

and ignore 'isDirectoryCreated'

2) (Recommended)

 boolean isDirectoryCreated=path.exists();
 if (!isDirectoryCreated) {
     isDirectoryCreated= path.mkdir();
 }
 if(isDirectoryCreated) {
    // do something
 }

3)

if (!path.exists()) {
   if(path.mkdir()){
     // do something
   }
}

"Result of method is ignored"- what does this imply?, that the (compilation) warning message really says this: Result of File.mkdir() is ignored. something like that. It is telling you that you are  The file transferring to my upload folder is working well but I have a warning in mkdir. It says file exist but the picture and folder generates own name. I don't know what warning is determining.

If you want to ignore this warning, add this on the method: @SuppressWarnings("all")

Result of 'File.mkdirs()' is ignored, mkdirs()' is ignored. i try To this Warning but i failed. private void saveGIF()  mode is ignored on Windows. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask(). recursive. Allows the creation of nested directories specified in the pathname. context

I created a utility function:

@SuppressWarnings("unused")
private static void IGNORE_RESULT(boolean b) {}

And then to use:

IGNORE_RESULT(path.mkdir());

I like this solution because it is self documenting. You are explicitly stating that you know there is a result and you are intentionally ignoring it. It should also optimize out to a NOP during compilation so there is no unnecessary test at runtime just to suppress a useless warning.

WARNING: File.mkdir() is ignored, 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  The java.io.File.mkdirs() creates the directory named by this abstract pathname, including necessary and non-existent parent directories. The method returns true if the directories was created, with all necessary parent directories; else false

java.io.File.mkdirs java code examples, File.mkdirs (Showing top 20 results out of 74,790) getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); WARNING, "Failed to touch "+file); } } isDirectory())or simply ignore the return value from this method and simply call  Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined; _tmkdir: _mkdir: _mkdir: _wmkdir

java.io.File.mkdir java code examples, getExternalStorageDirectory() + "/map"); boolean success = true; public static void mkdir(File dir) throws IOException { if (dir.exists()) { if (!dir. getPath()); if (!​success) { LOGGER.warning("failed to create symlink from " + isDirectory())or simply ignore the return value from this method and simply call #isDirectory. The Warnings Filter¶. The warnings filter controls whether warnings are ignored, displayed, or turned into errors (raising an exception). Conceptually, the warnings filter maintains an ordered list of filter specifications; any specific warning is matched against each filter specification in the list in turn until a match is found; the filter determines the disposition of the match.

Is mkdir -p totally safe when creating folder already exists, Each dir operand that names an existing directory shall be ignored without error. and if there When I execute mkdir -p folder I won't see any errors even warnings. You will see touch x mkdir -p x mkdir: cannot create directory 'x': File exists. To get used to using vivado for programming my cora z7-10, I wrote a simple program in VHDL. Everything works as it should, but I get the warning: "[Constraints 18-5210] No constraints selected for write." after the sythesis stage. I'm unable to find information on the warning (of a level I can understand, as I'm quite new to using FPGA's).