返回列表

webkitRequestFileSystem

默认分类 2018/02/05 17:19

代码如下:

function onInitFs(fs) {

  fs.root.getFile('log.txt', {create: true}, function(fileEntry) {

    // Create a FileWriter object for our FileEntry (log.txt).
    fileEntry.createWriter(function(fileWriter) {

      fileWriter.onwriteend = function(e) {
        console.log('Write completed.');
      };

      fileWriter.onerror = function(e) {
        console.log('Write failed: ' + e.toString());
      };

      // Create a new Blob and write it to log.txt.
      var blob = new Blob(['Lorem Ipsum'], {type: 'text/plain'});

      fileWriter.write(blob);

    }, e => alert('4 * 1024' + e));

  }, e => alert('4 * 1024' + e));

}

window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, e => alert('4 * 1024' + e));

http://houzhiqingjava.blog.163.com/blog/static/167399507201431894210152/

https://www.html5rocks.com/en/tutorials/file/filesystem/

window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.PERSISTENT,
  function(used, remaining) {
    if (remaining == "") {
      alert("未申请空间。");
    } else {
      alert("已使用空间" + used);
      alert("全部空间" + remaining);
    }
  },
  e => alert('4 * 1024' + e));