使用 Expo 的 FileSystem readasStringAsync 读取本地 .txt 文件

db1*_*048 5 javascript xml react-native expo

我正在尝试使用 expo 的 FileSystem readasStringAsync 函数在 react native 中读取本地 .txt 文件,并且遇到以下错误, Location ‘file:///C:/Users/User/Documents/folder/Untitled.txt’ isn’t readable.

话虽如此,当我控制单击 uri 时,它会打开 .txt 文件。这是我正在使用的代码,

import * as FileSystem from ‘expo-file-system’;
(async () =>{
const response = await FileSystem.readAsStringAsync( ‘file:///C:/Users/User/Documents/folder/Untitled.txt’ ).catch(
error =>{console.error(error)})
const quotes = response.json()
console.log(quotes)
})() 
Run Code Online (Sandbox Code Playgroud)

我想知道是否有人可以帮助我解决这个问题,或者可以提出一种将本地 .txt 文件转换为字符串的更好方法。谢谢

小智 -8

您不能await在异步函数中使用,请.then在 Promise 中使用