日期:2014-05-16  浏览次数:20369 次

用JavaScript读取文件内容
这个方法用于读取txt文件:
  function ReadFile(filespec){ //传入的参数是文件所在路径

  var fso  = new ActiveXObject("Scripting.FileSystemObject");

  var file = fso.OpenTextFile(filespec);

  var text = file.ReadLine();

  file.Close();

  alert("Text content:"+text);

  }

  这个方法用于读取二进制文件:

  function ShowFileInfo(filespec){ //传入的参数是文件所在路径

  var fso  = new ActiveXObject("Scripting.FileSystemObject");

  var file = fso.GetFile(filespec);

  var text = f.DateCreated;

  alert("Text content:"+text);

  }