https://github.com/itinance/react-native-fs //GitHub地址
具体用法参照GitHub
一.下载依赖
npm install react-native-fs --save
二.链接原生库
链接后重新编译,如果android还是报错用AS打开项目的Mainapplication.java文件夹,如果看到红字等找不到包的可把鼠标放上去,Alt+enter弹出解决
react-native link react-native-fs
三导入依赖
var RNFS = require('react-native-fs');
四.系统的几种路径:
MainBundlePath (String) The absolute path to the main bundle directory 。安卓undefined或报错,支持ios,主要bundle目录.
CachesDirectoryPath (String) The absolute path to the caches directory。ios和安卓都可用,缓存目录。
DocumentDirectoryPath (String) The absolute path to the document directory。ios和安卓都可用,文档目录.
TemporaryDirectoryPath (String) The absolute path to the temporary directory (iOS and Windows only)。
LibraryDirectoryPath (String) The absolute path to the NSLibraryDirectory (iOS only);
ExternalDirectoryPath (String) The absolute path to the external files, shared directory (android only)。外部存储目录android
ExternalStorageDirectoryPath (String) The absolute path to the external storage, shared directory (android only)
五.列出文件列表
base是自定义方法(不要误解),里面的东西才是我们要看的列出文件列表的代码。
base(){
RNFS.readDir(RNFS.Documen