使用FileSystem API编写文件 [英] write a file using FileSystem API

查看:209
本文介绍了使用FileSystem API编写文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用文件系统API创建一个文件..我用Google搜索并获得代码

I am trying to create a file using the File system API..i googled and i get a code

function onFs(fs) {

  fs.root.getFile('log.txt', {create: true, exclusive: true},
      function(fileEntry) {
           fileEntry.getMetaData(function(md) {
            }, onError);

      },
      onError
  );
}

window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, onFs, onError);

任何人都可以说什么是作为函数参数传递的fs ..

can any one say what is the fs which is passed as function argument..

请给我一个很好的例子......

Please refer me a good example...

推荐答案

fs 是一个javascript对象,允许你对虚拟文件系统进行类似系统级别的调用。

fs is a javascript object that allows you to make "system-like" level calls to a virtual filesystem.

所以你可以使用 fs 对象,用 fs.root.getFile(...) .getFile(...)方法中的第三个参数(在您的情况下,来自上面代码段的以下代码行)碰巧是成功获取的回调文件参考。

So for instance you can use the fs object to create/get a reference to a file in the virtual filesystem with fs.root.getFile(...). The third argument (in your case, the following lines of code from your above snippet) in the .getFile(...) method happens to be a callback for successful obtaining of a file reference.

function(fileEntry) {
       fileEntry.getMetaData(function(md) {
        }, onError);
}

该文件引用(在您的情况下称为 fileEntry )可以有各种方法调用,例如 .createWriter(...)用于写入文件, .file( ...)用于读取文件, .remove(...)用于删除文件。您的方法调用 .getMetaData(...),其中包含文件大小和修改日期。

That file reference (in your case it is called fileEntry) can have various methods called such as .createWriter(...) for writing to files, .file(...) for reading files and .remove(...) for removing files. Your method calls .getMetaData(...) which contains a file size and modification date.

更多细节以及html5文件系统API上的一些好示例您可能会发现以下文章有用探索文件系统API

For more specifics as well as some good examples on the html5 file-system api you may find the following article helpful Exploring the File-System API

文件的位置因浏览器,操作系统和存储类型而异(持久性与临时相关但是以下链接也非常有用 Chrome持久存储位置

The location of the files differs on the browser, operating system and storage type (persistent vs. temporary) but the following link has served to be quiet useful as well Chrome persistent storage locations

这篇关于使用FileSystem API编写文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆