3

I want to read the cell numbers from the text file in Android using react native and convert all data to string.

Right now I am here:

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>
    );
  }

I get text {"_40":0,"_65":0,"_55":null,"_72":null} which is i don't know where it is coming from.

Please someone put the working example.

Imran Noor
  • 371
  • 4
  • 20

1 Answers1

2

It Worked....

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)} />
Imran Noor
  • 371
  • 4
  • 20