1

您好,我在下面提到了使用 Firefox 浏览器在本地驱动器上创建 txt 文件的代码,但它不起作用,请帮我解决这些问题

function WriteTest() {
    var sFileContent="Dhaval Patel Tried to make life easy";
    var sFilePath="C:/Users/Dhaval Patel/Desktop/RFQ Forms/Test.txt";
    alert(sFilePath +"  "+sFileContent);
    try {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    }   
    catch (e) {
        alert("Permission UniversalXPConnect denied.");
    }
    file=Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
    file.initWithPath(sFilePath);
    file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE,420);
    outputStream=Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream);
    outputStream.init(file,0x04|0x08|0x20,420,0);
    outputStream.write(sFileContent, sFileContent.length);
    outputStream.close();
}
4

0 回答 0