diff --git a/entry/src/main/cpp/FileAccessMethods.cpp b/entry/src/main/cpp/FileAccessMethods.cpp index 4c588e88fd64d4d0a26a8f574e96e24e3b4255d0..c1dc5b38b02261c241c2ab461a7897f652c03043 100644 --- a/entry/src/main/cpp/FileAccessMethods.cpp +++ b/entry/src/main/cpp/FileAccessMethods.cpp @@ -26,17 +26,19 @@ const int DOMAIN = 0xFF00; const char *TAG = "[FileAccessMethods]"; // [Start napi_value] +// entry/src/main/cpp/FileAccessMethods.cpp static napi_value TransferSandboxPath(napi_env env, napi_callback_info info) { size_t argc = 2; napi_value argv[2] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - + //Convert the sandbox path and the contents of the text to be written into C-side variables through the Node-API interface. size_t pathSize, contentsSize; char pathBuf[256], contentsBuf[256]; // [Start get_path] napi_get_value_string_utf8(env, argv[0], pathBuf, sizeof(pathBuf), &pathSize); napi_get_value_string_utf8(env, argv[1], contentsBuf, sizeof(contentsBuf), &contentsSize); // [End get_path] + //Open the file through the specified path. snprintf(pathBuf, sizeof(pathBuf), "%s/TransferSandboxPath.txt", pathBuf); // [Start fp] FILE *fp; @@ -48,6 +50,7 @@ static napi_value TransferSandboxPath(napi_env env, napi_callback_info info) { } OH_LOG_Print(LOG_APP, LOG_INFO, DOMAIN, TAG, "Open file successfully!"); // [Start contentsBuf] + //Write a file using the file operation function of the C standard library. fprintf(fp, "%s", contentsBuf); // [End contentsBuf] fclose(fp); @@ -158,6 +161,7 @@ static napi_value WriteFileUsingPickerFd(napi_env env, napi_callback_info info) } // [End write_pick] // [Start read_file_pick] +// entry/src/main/cpp/FileAccessMethods.cpp static napi_value ReadFileUsingPickerFd(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value argv[1] = {nullptr};