Save textfile by JS

Junichi Ohnishi's icon

Dear Max user : I want to save some string data to text file by Ja Javascript. I wrote the code below and it seems to run well. Please tell me if there is any mistake.
var str="foo";
function save(filename) {
var f = new File(filename, "write", "TEXT");
if(f.isopen) {
post("file open succeeded\n");
f.writestring(str);
f.eof = f.position;
f.close();
post("file is saved\n");
}
else {
post("file open failed\n");
}
}