从react本地的文本下载txt文件
我正在尝试从文本下载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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
记录路径并检查试图存储的位置。对我来说,它显示了在我尝试存储
$ {rnfs.documentDirectoryPath} /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
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
.