Using “FSO” in Javascript, how to write a variables's content to a file? [duplicate]

[亡魂溺海] 提交于 2019-12-20 07:51:03

问题


Possible Duplicate:
how to write a variables's content to a file in JavaScript

I have this piece of code to create a text file. How can I write to this text file?

function makefile() { 

    var fso; 

    var thefile;

    fso = new ActiveXObject("Scripting.FileSystemObject");
    thefile=fso.CreateTextFile("C:\\tmp\\MyFile.txt",true);

    thefile.close()
}

回答1:


Here's one way:

makefile();

function makefile () {

    var fso = new ActiveXObject("Scripting.FileSystemObject"),
        thefile=fso.CreateTextFile("C:\\temp\\MyFile.txt",true);

    thefile.WriteLine('abc');
    thefile.Close();
}



回答2:


Bear in mind this will only work in IE with the correct "relaxed" security permissions.

All the information can be found under FileSystemObject Basics.

When you CreateTextFile (or OpenAsTextStream in write mode) you get a TextStream object back which has a WriteLine method, among others. Please see the examples for "the code".

Happy coding.



来源:https://stackoverflow.com/questions/6106312/using-fso-in-javascript-how-to-write-a-variabless-content-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!