Javascript写入文件系统 [英] Javascript Write to File System

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

问题描述

我需要写入Web应用程序的文件系统.请不要回答您不能这样做",因为它没有帮助.我看到可以用HTML5,php,python等来完成.我只是在做1个基本的写操作.书面文件是由搜索引擎抓取的,这就是为什么我有这个奇怪的要求的原因.

I need to write to the file system of my web application. Please don't respond "you can't do that" because it isn't helpful. I see that it can be done with HTML5, php, python, etc. I am just doing 1 basic write. The written file is crawled by a search engine, which is why I have this weird requirement.

要执行文件读取,请执行以下操作:

To perform the file read I do something like this:

$.ajax({
    type: "POST",
    url: "./engine-text.txt",
    dataType: "text",
    async: false,
    success: function (data) {
       text_data = data;
    }
});

我想做一些简单的事情.我只是在此文件中添加或删除多行文本并将其写回.就目前而言,我没有php或python.我基本上有JQuery,HTML5和Ruby.请记住,另一个程序需要能够读取此文件,因此我认为HTML5无法正常工作.谢谢!

I'd like to do something simple to write. I'm just adding or removing lines of text to this file and writing it back. As it stands I don't have php or python. I basically have JQuery, HTML5, and Ruby. Remember another program needs to be able to read this file, so I don't think HTML5 will work. Thanks!

推荐答案

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

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进行本地文件访问

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

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