我正在尝试使用 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)
})()
我想知道是否有人可以帮助我解决这个问题,或者可以提出一种将本地 .txt 文件转换为字符串的更好方法。
谢谢
最佳答案
你不能使用 await
在异步函数中,使用 .then
在 promise 中
关于javascript - 使用 Expo 的 FileSystem readasStringAsync 读取本地 .txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59492700/