开发者

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

开发者 https://www.devze.com 2023-03-08 09:17 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: how to write a variables's content to a file in JavaScript
This question already has answers here: Closed 11 years ago.

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 =开发者_JAVA技巧 new ActiveXObject("Scripting.FileSystemObject");
    thefile=fso.CreateTextFile("C:\\tmp\\MyFile.txt",true);

    thefile.close()
}


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();
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消