从react本地的文本下载txt文件

发布于 2025-01-28 12:19:19 字数 422 浏览 1 评论 0原文

我正在尝试从文本下载TXT文件,但是该功能无法正常工作。

txt函数

import RNFS from 'react-native-fs';

  const txtDownload = () => {
    let path = `${RNFS.DocumentDirectoryPath}/${filename}.txt`;
    RNFS.writeFile(path, `Here is text`, 'utf8').then((res) => {
      Toast('File saved successfully');
    }
    ).catch((err) => {
      Toast(err);
    });
  }

它返回成功保存的文件,但我找不到文件

I'm trying to Download txt file from a text but that function is not working fine.

Txt Function

import RNFS from 'react-native-fs';

  const txtDownload = () => {
    let path = `${RNFS.DocumentDirectoryPath}/${filename}.txt`;
    RNFS.writeFile(path, `Here is text`, 'utf8').then((res) => {
      Toast('File saved successfully');
    }
    ).catch((err) => {
      Toast(err);
    });
  }

It returns File saved successfully but I can't find file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-04 12:19:19

记录路径并检查试图存储的位置。对我来说,它显示了在我尝试存储$ {rnfs.documentDirectoryPath} /help.txt时,如下所示的位置

/data/user/0/com.sample/files/help.txt

。我不知道您是否可以写入文档文件夹。但它适用于使用rnfs.downloaddirectorypath的下载文件夹。

Log the path and check the location where it's trying to store. For me, it shows the location as below when I try to store in ${RNFS.DocumentDirectoryPath}/help.txt

/data/user/0/com.sample/files/help.txt

I suspect you were checking in the Documents folder. I don't know if you can write to the Documents folder. But it works for the Download folder using RNFS.DownloadDirectoryPath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文