警告:File.mkdir() 被忽略 [英] WARNING: File.mkdir() is ignored

查看:84
本文介绍了警告:File.mkdir() 被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Media Recorder API 创建了一个基本的录音应用程序.我正在尝试在 SD 卡中创建一个文件夹并将我录制的文件保存到该文件夹​​中.我通过以下代码收到此警告.

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() 被忽略

    // 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:

File.mkdir() 的结果被忽略

Result of File.mkdir() is ignored

...或类似的东西.它告诉您您忽略了 mkdir() 调用的结果,该调用告诉您是否创建了目录.

... 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.

既然你问了......对Java变量名使用匈牙利表示法是不好的风格.Java 是一种强类型语言,其中所有变量都有明确的声明类型.您不应该需要一些可怕的标识符约定的心理拐杖来告诉您变量的类型是什么.

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.

这篇关于警告:File.mkdir() 被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆