From e0e238e397748c335de685309a187149534f5cda Mon Sep 17 00:00:00 2001 From: WX1379483 Date: Wed, 28 May 2025 15:47:23 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9NativeFileAccess=E4=BB=93=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/FileAccessMethods.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/entry/src/main/cpp/FileAccessMethods.cpp b/entry/src/main/cpp/FileAccessMethods.cpp index 4c588e8..c1dc5b3 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}; -- Gitee