我想使用react native从Android的文本文件中读取单元格编号并将所有数据转换为字符串。
现在我在这里:
import RNFS from "react-native-fs";
const rootPath = RNFS.DocumentDirectoryPath;
readFile = async () => {
const path = rootPath + "/rn.txt";
var content = await RNFS.readFile(path, "utf8");
return content;
};
render() {
return (
<View style={styles.container}>
<Text>{JSON.stringify(this.readFile())}</Text>
</View>
);
}
我收到文本{“ _40”:0,“ _ 65”:0,“ _ 55”:null,“ _ 72”:null},我不知道它来自哪里。
请有人举个可行的例子。
答案 0 :(得分:1)
有效。...
readFile = async (MyPath) => {
try {
const path =MyPath+ "/rn.txt";
const contents = await RNFS.readFile(path, "utf8");
return("" + contents);
} catch (e) {
alert("" + e);
}
};
<Button title="AppFilesDir" onPress={() => this.readFile(RNFS.ExternalDirectoryPath)} />
<Button title="InternalStorageDir" onPress={() => this.readFile(RNFS.ExternalStorageDirectoryPath)} />