一、安装依赖
install
npm install react-native-fs --save
link
react-native link react-native-fs
如果link失败,或者link之后仍旧不能import,则考虑手动link,详情查看官网教程,传送门。(温馨提示:新install依赖之后,记得重启一下app——react-native run-ios //Android react-native run-android)
二、使用例子
1. 获得文件夹路径
import RNFS from 'react-native-fs';
//打印出常用路径
printPaths = () => {
console.log('MainBundlePath=' + RNFS.MainBundlePath)
console.log('CachesDirectoryPath=' + RNFS.CachesDirectoryPath)
console.log('DocumentDirectoryPath=' + RNFS.DocumentDirectoryPath)
console.log('TemporaryDirectoryPath=' + RNFS.TemporaryDirectoryPath)
console.log('LibraryDirectoryPath=' + RNFS.LibraryDirectoryPath)
console.log('ExternalDirectoryPath=