代码之家  ›  专栏  ›  技术社区  ›  Perraco

关闭一个使用Java文件描述符的C++文件指针

  •  1
  • Perraco  · 技术社区  · 6 年前

    在本机代码中使用从 ParcelFileDescriptor ,本机端是否应该使用 关闭 之后 ?

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

    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 回复  |  直到 6 年前
    推荐文章