I am trying to create a text file using react native for both Android and iOS device. How can we store the string data in text file and and save it to external storage of device. Please suggest if any library for the same.
            Asked
            
        
        
            Active
            
        
            Viewed 2.1k times
        
    7
            
            
        - 
                    Check out [react-native-fs](https://github.com/itinance/react-native-fs) library. – x4h1d Dec 10 '18 at 08:16
- 
                    You need to encrypt that file. Android providing Chrio class for encryption/decryption here is the link: https://stackoverflow.com/questions/4275311/how-to-encrypt-and-decrypt-file-in-android – bimal May 18 '20 at 07:27
1 Answers
13
            
            
        Use npm package react-native-fs for it..!
Install :
npm i react-native-fs
Creating File Example :
var RNFS = require('react-native-fs');
 
var path = RNFS.DocumentDirectoryPath + '/test.txt';
 
// write the file
RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')
  .then((success) => {
    console.log('FILE WRITTEN!');
  })
  .catch((err) => {
    console.log(err.message);
  });
 
    
    
        Community
        
- 1
- 1
 
    
    
        Praz Solver
        
- 513
- 3
- 12
- 
                    3Thanks Praz for your help. I have checked with code and getting the log of FILE WRITTEN. But I am able to view the file in my android device. Please help – pradip_android Dec 17 '18 at 11:13
