gpt4 book ai didi

react-native - react native : How to create text file and save it to external storage

转载 作者:行者123 更新时间:2023-12-03 15:44:56 27 4
gpt4 key购买 nike

我正在尝试使用 React Native 为 Android 和 iOS 设备创建一个文本文件。我们如何将字符串数据存储在文本文件中并将其保存到设备的外部存储中。请建议是否有相同的图书馆。

最佳答案

使用 npm 包 react-native-fs为了它..!

安装 :

npm i react-native-fs

创建文件示例:
var RNFS = require('react-native-fs');

var path = RNFS.DocumentDirectoryPath + '/test.txt';

// write the file
RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')
.then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});

谢谢..!

~ 普拉兹

关于react-native - react native : How to create text file and save it to external storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53701424/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com