FileStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

FileStream

Alexandre BP
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.

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...

Thx for your help

alex
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: FileStream

Levente Uzonyi-2
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
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: FileStream

Alexandre BP
Thank you very much for your help.
The thing is that, when I  first got the exception, I deleted  the file manually in the Pharo folder so I'm pretty sure it doesn't exist.
Maybe that when I do: "aStream := FileStream newFileNamed:filename" Pharo looks everywhere in my computer than it might find a file named 'test' or with a part of it named which is 'test'...but the file was created in the Pharo folder so I assume it must look only there to find a file, no?
alex


2010/11/28 Levente Uzonyi <[hidden email]>
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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: FileStream

Mariano Martinez Peck
Alexandre, maybe you will receive more answers if you ask directly in the pharo mailing list instead of seaside, since Files doesn't have anything to do with seaside ;)

http://www.pharo-project.org/community

On Mon, Nov 29, 2010 at 10:20 PM, alexandre bp <[hidden email]> wrote:
Thank you very much for your help.
The thing is that, when I  first got the exception, I deleted  the file manually in the Pharo folder so I'm pretty sure it doesn't exist.
Maybe that when I do: "aStream := FileStream newFileNamed:filename" Pharo looks everywhere in my computer than it might find a file named 'test'

No, that shouldn't happen. What if you do  FileDirectory defaul newFileNamed: filename

does it work?

BTW..did you read Pharo by Example?  Because there is a whole chapter explaining Streams and files....I am very bad with them, I always forget how to do trivial things and I need to check there...

http://pharobyexample.org/

Cheers

Mariano
 
or with a part of it named which is 'test'...but the file was created in the Pharo folder so I assume it must look only there to find a file, no?

yes
 
alex


2010/11/28 Levente Uzonyi <[hidden email]>

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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: FileStream

Alexandre BP
You are right!
sorry I didn't know there were a different mailinglist for pharo.

cheers
alex

2010/11/30 Mariano Martinez Peck <[hidden email]>
Alexandre, maybe you will receive more answers if you ask directly in the pharo mailing list instead of seaside, since Files doesn't have anything to do with seaside ;)

http://www.pharo-project.org/community

On Mon, Nov 29, 2010 at 10:20 PM, alexandre bp <[hidden email]> wrote:
Thank you very much for your help.
The thing is that, when I  first got the exception, I deleted  the file manually in the Pharo folder so I'm pretty sure it doesn't exist.
Maybe that when I do: "aStream := FileStream newFileNamed:filename" Pharo looks everywhere in my computer than it might find a file named 'test'

No, that shouldn't happen. What if you do  FileDirectory defaul newFileNamed: filename

does it work?

BTW..did you read Pharo by Example?  Because there is a whole chapter explaining Streams and files....I am very bad with them, I always forget how to do trivial things and I need to check there...

http://pharobyexample.org/

Cheers

Mariano
 
or with a part of it named which is 'test'...but the file was created in the Pharo folder so I assume it must look only there to find a file, no?

yes
 
alex


2010/11/28 Levente Uzonyi <[hidden email]>

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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: FileStream

Mariano Martinez Peck


On Tue, Nov 30, 2010 at 5:22 PM, alexandre bp <[hidden email]> wrote:
You are right!
sorry I didn't know there were a different mailinglist for pharo.


no problem, it was just for you, for me it is the same ;)
 
cheers
alex

2010/11/30 Mariano Martinez Peck <[hidden email]>

Alexandre, maybe you will receive more answers if you ask directly in the pharo mailing list instead of seaside, since Files doesn't have anything to do with seaside ;)

http://www.pharo-project.org/community

On Mon, Nov 29, 2010 at 10:20 PM, alexandre bp <[hidden email]> wrote:
Thank you very much for your help.
The thing is that, when I  first got the exception, I deleted  the file manually in the Pharo folder so I'm pretty sure it doesn't exist.
Maybe that when I do: "aStream := FileStream newFileNamed:filename" Pharo looks everywhere in my computer than it might find a file named 'test'

No, that shouldn't happen. What if you do  FileDirectory defaul newFileNamed: filename

does it work?

BTW..did you read Pharo by Example?  Because there is a whole chapter explaining Streams and files....I am very bad with them, I always forget how to do trivial things and I need to check there...

http://pharobyexample.org/

Cheers

Mariano
 
or with a part of it named which is 'test'...but the file was created in the Pharo folder so I assume it must look only there to find a file, no?

yes
 
alex


2010/11/28 Levente Uzonyi <[hidden email]>

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
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside