新闻内容
把字典保存到文件的问题
SmalltalkPower 于 2006年12月19日(星期二) 下午12时53分 在 comp.lang.smalltalk 上问道:
我想知道如何把一个字典保存到一个文件中。我的对象是一个字典的字典。
Reinout Heeck 于 2006年12月19日(星期二) 下午9时19分 回复说:
如果你不在乎文件格式,你可以用你所用的方言中原生的对象串行化器。
在 VisualWorks 中,可以这样做:
dict := Dictionary new.
dict2 := Dictionary new.
dict at: #one put: dict2.
"dict2 at: #parent put: dict." "if you uncomment this Trippy cannot
show the dicts, but BOSS still works"
encoder := BinaryObjectStorage onNew: 'foo.boss' asFilename writeStream.
encoder
nextPut: dict;
close.
decoder := BinaryObjectStorage onOld: 'foo.boss' asFilename readStream.
dict3 := decoder next.
decoder close.
dict3 inspect.
Andy Bower 于 2006年12月19日(星期二) 下午10时49分 回复说:
类似的,如果你有一个特定的文件格式,你可以在 Dolphin 中这样做:
dict := Dictionary new.
dict2 := Dictionary new.
dict at: #one put: dict2.
dict binaryStoreOn: (FileStream write: 'foo.stb' text: false).
dict3 := Object binaryReadFrom: (FileStream read: 'foo.stb' text: false). dict3 inspect.
