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

标签 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)
})() 

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

最佳答案

你不能使用 await在异步函数中,使用 .then在 promise 中

关于javascript - 使用 Expo 的 FileSystem readasStringAsync 读取本地 .txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59492700/

相关文章:

javascript - heroku Node js监听同一端口

javascript - 在 Firefox 中禁用通知的警报声音

c# - Selectnodes 只获取第一个节点

react 原生 map : MapView with the Animated API is lagging too much in android

javascript - 验证 2 个复选框和 2 个文本框以及一种日期格式

javascript - 将 js css 等其他文件包含到 html 中

c# - 如何在 C# 中获取元素中的 XML 属性

javascript - 自动完成/组件的动态图像

javascript - 使用循环更改组件特征(样式)

javascript - 模拟单元测试的 express-rate-limit