import RNFS from 'react-native-fs';
var path = RNFS.DocumentDirectoryPath + '/test.txt';
RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')
.then(success => {
console.log('FILE WRITTEN!');
})
.catch(err => {
console.log(err.message);
});
console.log(RNFS.DocumentDirectoryPath)
// /data/data/xxx.xxx.xxx/files/
但是我没有在手机的data
目录中找到像/data/xxx.xxx.xxx/files/
这样的路径/文件
但是代码中的条目存在
RNFS.readDir(RNFS.DocumentDirectoryPath).then(result => {
console.log('DocumentDirectoryPath GOT RESULT', result);
});
我想知道RNFS.DocumentDirectoryPath
在手机里的路径是什么?
发布于 2019-12-06 15:03:06
试试这条路
RNFS.readDir(RNFS.DocumentDirectoryPath)
.then((result) => {
console.log('GOT RESULT', result);
})
发布于 2019-12-10 23:57:42
首先,你需要检查文件是否存在
const filePath = RNFS.DocumentDirectoryPath + "/test" + ".txt";
RNFS.exists(filePath)
.then(success => {
if (success) {
readFile(filePath, logData);
} else {
writeFile(filePath, logData);
}
})
.catch(err => {
console.log(err.message, err.code);
});
const readFile = (filePath, logData) => {
RNFS.readFile(filePath, "utf8")
.then(content => {
// Do what you need if the file exists
})
.catch(err => {
console.log(err.message, err.code);
});
};
const writeFile = (filePath, logData) => {
RNFS.writeFile(filePath, logData, "utf8")
.then(() => {
// This will create new file for you in the name of test.txt
})
.catch(err => {
console.log(err.message, err.code);
});
};
发布于 2021-10-19 06:01:03
用于在移动存储中查找文件。您必须使用外部目录路径
文档的目录路径可以在android模拟器中找到。
数据路径-设备资源管理器/‘您的包名’,例如:‘com.’/
//您有您的文件
https://stackoverflow.com/questions/59208084
复制相似问题