我正在尝试使用 React Native 为 Android 和 iOS 设备创建一个文本文件。我们如何将字符串数据存储在文本文件中并将其保存到设备的外部存储中。请建议是否有相同的图书馆。
小智 10
使用 npm 包react-native-fs吧..!
安装 :
npm i react-native-fs
Run Code Online (Sandbox Code Playgroud)
创建文件示例:
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);
});
Run Code Online (Sandbox Code Playgroud)
谢谢..!
~ 普拉兹
| 归档时间: |
|
| 查看次数: |
11108 次 |
| 最近记录: |