将文件放在react-native项目中的位置,因此我可以使用react-native-fs(Android)访问它

问题描述 投票:0回答:1

我正在研究一个反应原生的项目。我有一个文件,我想使用react-native-fs库访问。该文件名为“chart.html”,我希望通过以下方式获取其路径:

'file://' + RNFS.DocumentDirectoryPath + '/chart.html';

我已经尝试将文件放在根目录,android / app,android / app / src和android / app / src / main中,到目前为止没有成功。

我在哪里放置文件,以便上面的代码工作?谢谢。

android reactjs react-native
1个回答
1
投票

如果将文件放入“assets”文件夹并重新编译Android项目,则可以使用react-native-fs访问这些文件:

android/app/src/main/assets/

以下方法可能有助于您访问它们:

您还可以查看“existsAssets”和“copyFileAssets”,后者用于将文件放入Document-Folder,如果其他库可以使用这些文件而无需访问assets-folder本身。

© www.soinside.com 2019 - 2024. All rights reserved.