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 WriteStream
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.
Hans
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?
Levente
Hi Hans,
Tuesday, March 30, 2010, 9:43:06 PM, you wrote:
BH> Don't know... I just want the simple plain kind of file that Squeak used to produce....
I think this has to do with the transition to UTF8 which is slower and not understood everywhere.
You have to revert to StandardFileStream.
I just tried the following snippet from 3.8 in trunk: | fileStream | fileStream := StandardFileStream forceNewFileNamed: 'addedItems.txt'. fileStream ascii. fileStream nextPutAll: 'gagaÄÖÜßöäü'. fileStream close
and could open it in an old, non UTF8 aware editor.
HTH,
Herbert mailto:herbertkoenig@gmx.net
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 WriteStream
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 | file lineEndConvention: #crlf; 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 beginning:
FileStream newFileNamed: 'yourNewUTF8EncodedFile' do: [ :file | file binary. UTF8TextConverter writeBOMOn: file. file ascii; 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 image.)
If you really want the old way, use StandardFileStream instead of FileStream, but that will only work octet characters and byte strings.
Levente
Hans
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?
Levente
Thanks, Levente
Your first example worked fine for me! So latin1 is the encoding expected by many existing applications?
Hans
-----Original Message----- From: Levente Uzonyi [mailto:leves@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 WriteStream
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 | file lineEndConvention: #crlf; 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 beginning:
FileStream newFileNamed: 'yourNewUTF8EncodedFile' do: [ :file | file binary. UTF8TextConverter writeBOMOn: file. file ascii; 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 image.)
If you really want the old way, use StandardFileStream instead of FileStream, but that will only work octet characters and byte strings.
Levente
Hans
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?
Levente
squeak-dev@lists.squeakfoundation.org