Chinaunix首页 | 论坛 | 博客
  • 博客访问: 661996
  • 博文数量: 137
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 1335
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-23 15:18
文章分类

全部博文(137)

文章存档

2010年(2)

2009年(2)

2008年(2)

2007年(30)

2006年(99)

2005年(2)

我的朋友

分类: 系统运维

2006-03-23 17:42:52

实现了一个文件导出的script。
// 功能:打开文件对话框将参数text(为字符串)中的内容另存
function exportText(text) {
  var fp =  Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
  var stream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
  fp.init(window, "Select a File", fp.modeSave);
  fp.appendFilters(fp.filterText);
  if (fp.show() != fp.returnCancel) {
    if (fp.file.exists())
      fp.file.remove(true);
    fp.file.create(fp.file.NORMAL_FILE_TYPE, 0666);

    stream.init(fp.file, 0x02, 0x200, null);
    stream.write(text, text.length);
    stream.close();
 }
}
阅读(1947) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~