ex:savefile ="c:\\lan.txt";

function FileRead(savefile) {

 try {

  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

 } catch (e) {

  //alert("Permission to read file was denied.");

  ShowErrorMessage("Permission to read file was denied.");

 }

 var file = Components.classes["@mozilla.org/file/local;1"]

  .createInstance(Components.interfaces.nsILocalFile);

 file.initWithPath( savefile );

 if ( file.exists() == false ) {

  //alert("File does not exist");

 }

 var is = Components.classes["@mozilla.org/network/file-input-stream;1"]

  .createInstance( Components.interfaces.nsIFileInputStream );

 is.init( file,0x01, 00004, null);

 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]

  .createInstance( Components.interfaces.nsIScriptableInputStream );

 sis.init( is );

 var output = sis.read( sis.available() );

 //document.getElementById('blog').value = output;

 return output;

} 

狼翔月影 發表在 痞客邦 PIXNET 留言(0) 人氣()