2021年3月8日星期一

When I write a file in my ReactNative app it doesn't actually write

Sometimes, I need to read or write files to use the filesystem when I develop RN(React Native) project. react-native-fs is the library that I found here, with the promise to do the file read and save whole new file.

I perfectly ran everything of that library and looks like it's running great (no bugs in execution). But when I finally go to save my new file it doesn't does nothing with the file, the file keeps blank, but it's showing the massage "FILE WRITTEN!", the message that in the Promise of the code should be the one who shows that it the succesfully ran.

In my coding files it already has a test.txt, it's a whole new React Native app, follows the code:

import React from 'react';  import {Text, TouchableOpacity ,StyleSheet ,View} from 'react-native';  import * as RNFS from 'react-native-fs'  export const App = () => {    // directory of the file    var path = RNFS.DocumentDirectoryPath + '/test.txt';      // write the file    const onPress = () => RNFS.writeFile(path, 'Testing string to print in the file', 'ascii')    .then(() => {      console.log('FILE WRITTEN!');    })    .catch((err) => {      console.log(err.message);    });      return (      <View style={styles.container}>        <TouchableOpacity          style={styles.btnSend}          onPress={onPress}        >             <Text>Press Here</Text>        </TouchableOpacity>      </View>      );  };    const styles = StyleSheet.create({    container: {      flex: 1,      justifyContent: 'center',      alignItems: 'center',      backgroundColor: 'white',    }  

, btnSend: { alignItems: "center", backgroundColor: "#DDDDDD", padding: 10, margin: 10, } });

export default App;

https://stackoverflow.com/questions/66540659/when-i-write-a-file-in-my-reactnative-app-it-doesnt-actually-write March 09, 2021 at 12:04PM

没有评论:

发表评论