|
ale,
> Hi, i'm just starting to learn smalltalk.
Welcome, you've made a good choice :-)
> i'd like to know how to write the result of any computation that i
> write on a workspace, directly on a file.
> thanks
You create an instance of FileStream and then write to that. As in
fs := FileStream write: 'TheFileName.txt'.
[ | x |
x := 100 factorial.
fs
nextPutAll: 'The factorial of 100 is ';
print: x;
cr] ensure: [fs close]
The #ensure: block is not really necessary but makes sure that if there
is an error in your code you are not left with dangling open files.
Without the #ensure block you could just have
fs := FileStream write: 'TheFileName.txt'.
x := 100 factorial.
fs
nextPutAll: 'The factorial of 100 is ';
print: x;
cr.
fs close
--
Ian
Use the Reply-To address to contact me.
Mail sent to the From address is ignored.
|