[squeak-dev] Re: plain text file
Hans.Baveco at wur.nl
Wed Mar 31 13:27:11 UTC 2010
Your first example worked fine for me! So latin1 is the encoding expected by many existing applications?
From: Levente Uzonyi [mailto:leves at elte.hu]
Sent: woensdag 31 maart 2010 1:52
To: The general-purpose Squeak developers list
Subject: Re: [squeak-dev] Re: plain text file
On Tue, 30 Mar 2010, Baveco, Hans wrote:
> Don't know... I just want the simple plain kind of file that Squeak used to produce....
> I can't check it, but if I remember correctly I used something like:
> FileDirectory default forceNewFileNamed: aStringWithCompletePath to
> create the file stream, and filled it with the contents of a
> The resulting file can be opened with notepad etc, and looks OK, but MSWord asks for the encoding, and R (when run from the command line) refuses to open the file.
Here is an example using Latin1 encoding and #crlf line end conversion.
That means that every #cr will actually be written as crlf:
FileStream newFileNamed: 'yourNewLatin1EncodedFile' do: [ :file |
converter: Latin1TextConverter new;
nextPutAll: 'This is an example sentence with some Latin1 compatible characters: áéíóúöü.'; cr;
nextPutAll: 'This is a second example sentence.'; cr ].
If you don't set the line encoding it will not convert line endings. If you don't set the converter, it will use an UTF8TextConverter.
If you start your file with a Byte Order Mark, then most software will assume that it has UTF-8 encoding. The following example uses UTF-8 encoding and no conversion for line ending, it also writes BOM at the
FileStream newFileNamed: 'yourNewUTF8EncodedFile' do: [ :file |
UTF8TextConverter writeBOMOn: file.
nextPutAll: 'This is an example sentence with some Latin1 compatible characters: áéíóúöü.'; crlf;
nextPutAll: 'This is a second example sentence.'; crlf ].
(Note that sending #crlf to a Stream only works if you're using a 4.1
If you really want the old way, use StandardFileStream instead of FileStream, but that will only work octet characters and byte strings.
> On Tue, 30 Mar 2010, Baveco, Hans wrote:
>> How do I produce a plain text file that can be read by other programs,
>> e.g. R and MSWord? Do I have to define a specific encoding? How? Files
> Do you need a specific encoding? What about line endings?
>> created from VisualWorks are ok; files produces with default settings
>> from current Squeak (trunk) are not....
> How are you creating your file?
More information about the Squeak-dev