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

查看:4007
本文介绍了警告: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是一种强类型语言,其中所有变量都有明确的声明类型.您不需要某些令人毛骨悚然的标识符约定的精神cru语,就可以告诉您变量的类型是什么.

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天全站免登陆