关闭使用Java中文件描述符的C ++ FILE指针

时间:2018-08-25 23:25:29

标签: android java-native-interface fclose fdopen parcelfiledescriptor

在从ParcelFileDescriptor获取的本机代码中使用文件描述符时,本机端应在 fdopen 之后使用 fclose 吗?

ParcelaleFileDescriptor实例所拥有的documentation states拥有文件描述符,应该通过它关闭它。我不知道在关闭文件描述符之前关闭本机FILE指针的影响。

伪代码:

1) JAVA:
    // Obtain the file descriptor and pass it to the native method
    ParcelFileDescriptor descriptor  = contentResolver.openFileDescriptor(uri, "w");
    nativeMethod(descriptor.getFD());

2) C++:
    void nativeMethod(const int fd)
    {
        FILE* fp = fdopen(fd, "wb");    

        ..... // do something

        fclose(fp); // Close the file pointer <-- Is this valid?
    }

3) JAVA:
    // Back from the native method, close the file descriptor
    descriptor.close();

0 个答案:

没有答案
相关问题