且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript写入文件系统

更新时间:2022-11-30 13:59:21

通常出于安全考虑,您不能使用浏览器.

Generally you can't in your browser due to security concerns.

但是,这并不意味着您无法使用浏览器来使服务器运行它->例如,服务器端JavaScript Node.js.

However it doesn't mean you can't get your browser to make your server to do it -> eg Server Side JavaScript Node.js.

例如使用文件系统

var fs = require('fs');
fs.writeFile("yourpath", "Hello", function(err) {
    if(err) {
        console.log(err);
    } else {
        console.log("The file was saved!");
    }
});

某些浏览器现在允许通过File Api访问文件系统:

Some browsers do now allow File system access through the File Api:

https://developer.mozilla.org/zh-CN/docs/Web/API/File_and_Directory_Entries_API

请参阅此链接以获取更详细的答案:

see this link for a more detailed answer:

使用javascript进行本地文件访问