简体   繁体   English

Cordova插件中Assets文件夹中文件的路径

[英]Path to file in the Assets folder from within a Cordova plugin

I am using a plugin cordova-plugin-bluenet-dfu I put the required firmware directly within the www folder. 我正在使用插件cordova-plugin-bluenet-dfu ,将所需的固件直接放在www文件夹中。 However, I have trouble targeting the file correctly with either file path or URI. 但是,我无法使用文件路径或URI正确定位文件。

With filePath for example, the plugin in Java opens file the following way: filePath为例,Java中的插件通过以下方式打开文件:

final InputStream is = new FileInputStream(filePath);

I tried to specify the file by 我试图通过指定文件

file:///android_asset/www/firmware/sdk11_lock_20161215_resDelay.zip
android_asset/www/firmware/sdk11_lock_20161215_resDelay.zip
www/firmware/sdk11_lock_20161215_resDelay.zip

None of which seems to work. 这些似乎都不起作用。 I tried the first one with fileUri too and it doesn't work. 我也用fileUri尝试了第一个,它不起作用。

How do I specify the path to the file inside the the assets folder? 如何指定assets文件夹中文件的路径?

Cordova access your file as a relative path. Cordova将您的文件作为相对路径访问。 Mainly, Cordova think you're using the www directory. 主要是Cordova认为您正在使用www目录。 So if you want to find a file, ie myfile.html, you just use this filename if the file is in the www dir. 因此,如果要查找文件myfile.html,则只要该文件位于www目录中,就可以使用该文件名。 If the file is in the dir inside (ie www\\MyDirInside), you can access to it using MyDirInside\\myfile.html (Sincerely I don't remember if \\ or / ). 如果文件位于内部目录(即www \\ MyDirInside)中,则可以使用MyDirInside \\ myfile.html对其进行访问(因为我不记得\\或/)。

Let's try using your dir and files. 让我们尝试使用您的目录和文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM