Helene Bilbo
Helene Bilbo

Reputation: 1142

How to correctly decode text files from FileSystemReadStream in Pharo 1.4

In Pharo 1.4 i opened a FileSystemReadStream on a text file and transformed it to a String via aFileSystemReadStream contents asString.

My text files are UTF8 encoded and have those Windows (CR LF) linebreaks.

The resulting Pharo Strings have two linebreaks per text file line and some weird characters instead of german umlauts like Ä, Ö, Ü etc.

How can i correctly decode my text files in Pharo?

Upvotes: 6

Views: 540

Answers (1)

camillobruni
camillobruni

Reputation: 2318

Don't use FileSystemReadStreams in 1.4, they are not complete and buggy ;). Use FileStream instead.

multiByteFileStream := FileStream fileNamed: '/foo/bar.txt'.
multiByteFileStream contents.

It will return a MultiByteFileStream where you can set the line end convention and encoding:

multiByteFileStream 
    "possible values are: #cr #lf #crlf"
    lineEndConvention: #cr;
    "set a specific converter, see subclasses of TextConverter"
    converter: UTF8TextConverter new. 

Upvotes: 9

Related Questions