问题描述
我正在研究HTML5 FileSystem-API的教程。
基本上我想把文件写到我的机器上。我使用python的simpleHTTPServer来为网站服务。一旦我加载网页,控制台不会引发错误,我收到一条消息,表明写入成功。但我无法在我的机器上的任何地方找到该文件。这是我的代码:
I am working on the tutorial for HTML5 FileSystem-API.Basically I would like to write a file to my machine. I am using python's simpleHTTPServer to serve the website. Once I load the webpage, the console doesn't raise an error and I get a message that the write was successful. But I can't find the file anywhere on my machine. Here is my code:
function onInitFs(fs) {
fs.root.getFile('zz11zzlog.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);
}, errorHandler);
}, errorHandler);
}
function errorHandler(e) {
var msg = '';
switch (e.code) {
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'QUOTA_EXCEEDED_ERR';
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'INVALID_MODIFICATION_ERR';
break;
case FileError.INVALID_STATE_ERR:
msg = 'INVALID_STATE_ERR';
break;
default:
msg = 'Unknown Error';
break;
};
console.log('Error: ' + msg);
}
window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler);
推荐答案
如果写入成功,该文件将以chrome或chromium写入本地文件系统配置目录默认
- > 文件系统
目录。
If the write was successful, the file would be written to local filesystem at chrome or chromium configuration directory at Default
-> File System
directory.
请参阅
这篇关于HTML5 fileWriter.write不写入本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!