9

AndroidトレーニングセンターのWebサイトでこのコードを見ました:

boolean hasExternalStoragePrivateFile() {
    // Get path for the file on external storage.  If external
    // storage is not currently mounted this will fail.
    File file = new File(getExternalFilesDir(null), "DemoFile.jpg");
    if (file != null) {
        return file.exists();
    }
    return false;
}

それは Android でnew File()null を返すことができるということですか?

http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

4

1 に答える 1

13

いいえ、コンストラクターが null を返すことはありません。コンストラクターは、完全に初期化されたオブジェクトを返すか、例外またはエラーをスローします。

于 2013-03-18T10:16:36.090 に答える