本文介绍了如何阅读“资源"通过 Tizen IDE 添加的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Tizen 可穿戴设备编写 Web 应用程序的第一步.这就是我想要做的:

I'm giving my first steps on programming web apps for Tizen wearable devices . This is what I want to do :

  1. 通过使用 Tizen IDE,添加一个文件,例如x.txt ,在一个文件夹下,例如数据/文本(即项目根目录的相对路径是数据/文本/x.txt )
  2. 在运行时,我想读取 x.txt 的内容文件
  3. ...并用它做一些额外的处理.

我以为我可以读取 wgt-package 虚拟根但 我的代码(修复后)在该位置不返回任何文件.

I thought I could just read wgt-package virtual root but my code (after fixing it) returns no file at that location .

我怎么能这样做?顺便说一句,我一直在网络模拟器上进行测试.

How could I do this ? BTW , I've been testing on the web simulator .

附言我知道这很简单,所以我猜这应该记录在某个地方,但我搜索了一段时间后(从昨天开始)找不到参考,所以我希望有人能帮助我努力在正确的轨道上

p.s. I'm aware of the fact that this is quite simple , so guess this should be documented somewhere but I just could not find a reference after searching for a while (since yesterday), so I'm hoping someone can help me put my efforts on the right track

提前致谢!

推荐答案

请参阅下面的文件系统教程和 API 参考

see, below FileSystem Tutorial and API Reference

文件系统教程 https://developer.tizen.org/development/tutorials/web-application/tizen-features/base/filesystem#retrieve

文件系统 API 参考 https://developer.tizen.org/dev-guide/latest/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html#FileSystemManager::resolve

Filesystem API Reference https://developer.tizen.org/dev-guide/latest/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html#FileSystemManager::resolve

如果您将文本文件放在/project_root/data/text/x.txt 上.您可以使用 webapi 上的wgt-package/data/text/x.txt"路径访问该文件.

If you put your text file on /project_root/data/text/x.txt.You can access to that file with "wgt-package/data/text/x.txt" path on webapi.

下面是简单的示例代码.试试看.

So below is simple example code. try it.

 function onsuccess(files) {
   for (var i = 0; i < files.length; i++) {
     console.log("File Name is " + files[i].name); // displays file name

     if(file[i].name = "your_txt_file.txt"){
        //do something here. file[i].readAsText(....)
     }
   }
 }

 function onerror(error) {
   console.log("The error " + error.message + " occurred when listing the files in the selected folder");
 }

 tizen.filesystem.resolve(
     "wgt-package/data/text",
     function(dir) {
       documentsDir = dir; dir.listFiles(onsuccess,onerror);
     }, function(e) {
       console.log("Error" + e.message);
     }, "rw"
 );

这篇关于如何阅读“资源"通过 Tizen IDE 添加的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!