[Seaside] FileStream

Levente Uzonyi leves at elte.hu
Sun Nov 28 01:14:12 UTC 2010


On Sat, 27 Nov 2010, alexandre bp wrote:

> Hi,
>
> I'm having trouble with the FileStream....
>
> I have tried several things:
> filename := 'test'.
> aStream := StandardFileStream new.
> 1) aStream := FileStream newFileNamed:filename.
> 2) aStream := filename asFilename writeStream.
>
> 1) this solution worked one time but when I tried to create other
> files with other names (whatever the name) I get an exception:
> FileExistsException
> 2) doesn't work at all. I get an exception as well:
> MessageNotUnderstood: ByteString>>asFilename.

How to use FileStreams?

existingReadOnlyFile := FileStream readOnlyFileNamed: 'foo'. "raises an exception if the file doesn't exist"
existingReadableAndWriteableFile := FileStream oldFileNamed: 'foo'. "raises an exception if the file doesn't exist"
readableAndWriteableFile := FileStream fileNamed: 'foo'. "automatically creates the file if it doesn't exist"
newReadableAndWriteableFile := FileStream newFileNamed: 'foo'. "raises an exception if the file exists"
newReadableAndWriteableFile := FileStream forceNewFileNamed: 'foo'. "deletes the file if it exists"

All of these methods have a do: variant. For example:
FileStream readOnlyFileNamed: 'foo' do: [ :file | file contents "This will close the file and return it's contents." ].

When to use StandardFileStream?
Only when you don't need character encoding or line-end conversion.

>
> I don't know what to do.... I don't understand why I have the
> exception FileExistsException even thought the name I give to filename
> is different...

Are you sure that the file doesn't exist? Some systems (windows and most 
macs) are case insensitive, so if you have a file named 'TEST', then you 
also have 'test' and 'Test', etc.


Levente

>
> Thx for your help
>
> alex
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>


More information about the seaside mailing list