0
0
React Nativemobile~10 mins

File system access in React Native - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the file system module in React Native.

React Native
import [1] from 'react-native-fs';
Drag options to blanks, or click blank then click option'
AFileSys
BRNFS
Cfs
DFileSystem
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fs' which is a Node.js module, not React Native.
Using 'FileSystem' which is from Expo, not react-native-fs.
2fill in blank
medium

Complete the code to read a file's content as a string.

React Native
RNFS.readFile([1], 'utf8').then(contents => {
  console.log(contents);
});
Drag options to blanks, or click blank then click option'
AfilePath
BfileUri
CfileName
DfileData
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the file name without path, which causes file not found error.
Using 'fileUri' which is not the expected parameter here.
3fill in blank
hard

Fix the error in the code to write text to a file.

React Native
RNFS.[1](filePath, 'Hello World').then(() => {
  console.log('File written');
});
Drag options to blanks, or click blank then click option'
Awrite
BwriteText
CwriteFile
DsaveFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'write' which does not exist in react-native-fs.
Using 'writeText' or 'saveFile' which are invalid method names.
4fill in blank
hard

Fill both blanks to check if a file exists and then delete it.

React Native
RNFS.[1](filePath).then(exists => {
  if (exists) {
    RNFS.[2](filePath).then(() => console.log('Deleted'));
  }
});
Drag options to blanks, or click blank then click option'
Aexists
BfileExists
Cunlink
DdeleteFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fileExists' which is not a method in react-native-fs.
Using 'deleteFile' which is not the correct method name.
5fill in blank
hard

Fill all three blanks to create a directory, write a file inside it, and then read the file.

React Native
RNFS.[1](dirPath).then(() => {
  return RNFS.[2](filePath, 'Sample Text');
}).then(() => {
  return RNFS.[3](filePath, 'utf8');
}).then(contents => {
  console.log(contents);
});
Drag options to blanks, or click blank then click option'
Amkdir
BwriteFile
CreadFile
DcreateDir
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'createDir' which is not a method in react-native-fs.
Mixing up 'writeFile' and 'readFile' methods.