首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

firefox 资料操作

2012-11-23 
firefox 文件操作??? ??? ??? ??? var readFilefunction(path) {??? ??? ??? ??? ??? ??? var content

firefox 文件操作

??? ??? ??? ??? var readFile=function(path) {
??? ??? ??? ??? ??? ??? var content = "";
??? ??? ??? ??? ??? ??? try{
??? ??? ??? ??? ??? ??? ??? ??? var fso = new ActiveXObject("Scripting.FileSystemObject");
??? ??? ??? ??? ??? ??? ??? ??? var reader = fso.openTextFile(path, 1);
??? ??? ??? ??? ??? ??? ??? ??? while(!reader.AtEndofStream) {
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? content += reader.readline();
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? content += "\n";
??? ??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? ??? // close the reader
??? ??? ??? ??? ??? ??? ??? ??? reader.close();
??? ??? ??? ??? ??? ??? }catch(e){
??? ??? ??? ??? ??? ??? ??? ??? if(document.implementation && document.implementation.createDocument){
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? try {
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? var lf = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? lf.initWithPath(path);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? if (lf.exists() == false) {
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? alert("File does not exist");
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? var fis = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? fis.init(lf, 0x01, 00004, null);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? sis.init(fis);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? content = converter.ConvertToUnicode(sis.read(sis.available()));
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? converter.charset = "UTF-8";
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? //converter.charset = "GB2312";
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? catch (e) {
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? alert("Mozilla Firefox read local file error: \n" + e);
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? return content;
??? ??? ??? ??? };
??? ??? ??? ??? var writeFile=function(arrstr,path){
??? ??? ??? ??? ??? ??? try{
??? ??? ??? ??? ??? ??? ?? var fso? = new ActiveXObject("Scripting.FileSystemObject");
??? ??? ??? ??? ??? ??? ?? var fh = fso.CreateTextFile(path, true);
??? ??? ??? ??? ??? ??? ?? fh.WriteLine(arrstr);
??? ??? ??? ??? ??? ??? ?? fh.Close();
??? ??? ??? ??? ??? ??? }catch(e){
??? ??? ??? ??? ??? ??? ??? try {
??? ??? ??? ??? ??? ??? ??? ??? var pm = netscape.security.PrivilegeManager;
??? ??? ??? ??? ??? ??? ??? ??? pm.enablePrivilege('UniversalXPConnect');
??? ??? ??? ??? ??? ??? ??? }catch(e)
??? ??? ??? ??? ??? ??? ??? {
??? ??? ??? ??? ??? ??? ??? ??? alert("!!被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);

??? ??? ??? ??? ??? ??? ??? ?if(file instanceof Components.interfaces.nsILocalFile)
??? ??? ??? ??? ??? ??? ??? ?{
??? ??? ??? ??? ??? ??? ??? ??? file.initWithPath(path);
??? ??? ??? ??? ??? ??? ??? ??? }else
??? ??? ??? ??? ??? ??? ??? {
??? ??? ??? ??? ??? ??? ??? ??? alert("error");
??? ??? ??? ??? ??? ??? ??? ??? return;
??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
??? ??? ??? ??? ??? ??? ??? var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);

??? ??? ??? ??? ??? ??? ??? try
??? ??? ??? ??? ??? ??? ??? {???
??? ??? ??? ??? ??? ??? ??? ??? ?outputStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
??? ??? ??? ??? ??? ??? ??? }catch(e){
??? ??? ??? ??? ??? ??? ??? ??? alert(e);
??? ??? ??? ??? ??? ??? ??? ??? alert(arrstr);
??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? converter.init(outputStream, "UTF-8", 0, 0);
??? ??? ??? ??? ??? ??? ???
??? ??? ??? ??? ??? ??? ??? try
??? ??? ??? ??? ??? ??? ??? {
??? ??? ??? ??? ??? ??? ??? ??? converter.writeString(arrstr);
??? ??? ??? ??? ??? ??? ??? }catch(e){
??? ??? ??? ??? ??? ??? ??? ??? alert(e);
??? ??? ??? ??? ??? ??? ??? ??? alert(arrstr);
??? ??? ??? ??? ??? ??? ??? };
??? ??? ??? ??? ??? ??? ??? converter.close();
??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? };

热点排行