0
0
React Nativemobile~5 mins

File system access in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the react-native-fs library?
It provides an easy way to read, write, and manage files on a device's file system in React Native apps.
Click to reveal answer
beginner
How do you read a text file asynchronously using react-native-fs?
Use RNFS.readFile(path, 'utf8') which returns a promise with the file content as a string.
Click to reveal answer
intermediate
What is the difference between DocumentDirectoryPath and ExternalDirectoryPath in React Native file system?
DocumentDirectoryPath is private app storage, backed up and sandboxed. ExternalDirectoryPath is public external storage, accessible by other apps (Android only).
Click to reveal answer
beginner
Why should you handle permissions when accessing the file system on mobile devices?
Because mobile OSes restrict file access for security. You must request user permission to read/write files outside your app sandbox.
Click to reveal answer
beginner
What method would you use to check if a file exists before reading it in React Native?
Use RNFS.exists(path) which returns a promise resolving to true if the file exists, false otherwise.
Click to reveal answer
Which React Native library is commonly used for file system access?
Areact-native-gesture-handler
Breact-native-fs
Creact-native-maps
Dreact-native-camera
What does RNFS.readFile(path, 'utf8') return?
AA string with file contents
BA boolean indicating success
CAn error object
DA promise resolving to file contents
Which directory path is private and sandboxed for your app?
ACacheDirectoryPath
BExternalDirectoryPath
CDocumentDirectoryPath
DTemporaryDirectoryPath
Before reading a file, which method helps you check if it exists?
ARNFS.exists
BRNFS.readFile
CRNFS.writeFile
DRNFS.unlink
Why must you request permissions for file system access on mobile?
AFor security and privacy reasons
BTo access internet
CTo improve app speed
DTo enable push notifications
Explain how to read a text file in React Native using react-native-fs.
Think about asynchronous file reading with promises.
You got /4 concepts.
    Describe the difference between private and external storage paths in React Native file system.
    Consider where files are stored and who can access them.
    You got /4 concepts.