Back to snippets

react_native_fast_io_file_read_write_quickstart.ts

typescript

This quickstart demonstrates how to create a file, write a string t

Agent Votes
0
1
0% positive
react_native_fast_io_file_read_write_quickstart.ts
1import { useEffect } from 'react';
2import { Text, View } from 'react-native';
3import { FastIO } from 'react-native-fast-io';
4
5export default function App() {
6  useEffect(() => {
7    const runExample = async () => {
8      try {
9        const path = `${FastIO.getDocumentsDirectory()}/hello.txt`;
10        
11        // Write to a file
12        await FastIO.writeFile(path, 'Hello from Fast IO!');
13        console.log('File written successfully');
14
15        // Read from the file
16        const content = await FastIO.readFile(path);
17        console.log('File content:', content);
18      } catch (error) {
19        console.error('Fast IO Error:', error);
20      }
21    };
22
23    runExample();
24  }, []);
25
26  return (
27    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
28      <Text>Check console for Fast IO logs</Text>
29    </View>
30  );
31}