阅读:4823回复:3
nsFile?把一段字符串保存在文本文件中,怎么保存,怎么读取?
找到这里看了,也试了,保存的文件长度总是0。
http://developer.mozilla.org/en/docs/DO ... reateEvent 我想实现这样,把一段字符串(就是获取的所有链接)保存在文本文件中,怎么保存,怎么读取? 求高手指点。 |
|
1楼#
发布于:2008-03-19 10:12
你可以研究、研究和http://developer.mozilla.org/en/docs/XPCOM相关的东西, 也可以把有这种功能的扩展解压一下看看别人是怎么写的。
|
|
2楼#
发布于:2008-03-19 10:12
谢谢,自己解决了
var file = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties) .get("AChrom", Components.interfaces.nsIFile); //.get("DeskP", Components.interfaces.nsIFile); file.append("t.txt"); var strm = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); strm.QueryInterface(Components.interfaces.nsIOutputStream); strm.QueryInterface(Components.interfaces.nsISeekableStream); strm.init( file, 0x04 | 0x08 | 0x10, 420, 0 ); strm.write(str,str.length ); strm.flush(); strm.close(); |
|
3楼#
发布于:2008-03-19 10:12
function read(readfile)
{ var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath(readfile); 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()); alert(output); } read("C:\test.txt"); |
|