openlang

Writing a text file with smalltalk

I'm testing the following snippet:

entry := 'notes.txt' asFileReference.
writer := entry writeStream.
writer nextPutAll: 'hello world'.
writer close.
entry content.

Instead this exception appears:

**FileDoesNotExistException**

The conversation continues 2

Follow the reasoning
  1. Permalink
    'notes.txt' asFileReference
      writeStreamDo: [ :sink | sink << 'Hello, World!' ].

    That ought to succeed. However, it expresses your earlier approach differently, which makes me suspect incorrect write permissions or a related issue somewhere in the environment.

  2. Permalink

    Adding something to Elain's reply, an unexpected detail in Pharo is how writeStreamDo writes over a file, leaving a combination of the replacement contents and the previous contents' ending whenever the old file contains more data than its replacement. Luckily, fixing this is straightforward: just add truncate to the block. Here is a somewhat more "safe" alternative:

    'notes.txt' asFileReference
      writeStreamDo: [ :sink | sink truncate. sink << 'Hello, World!' ].

Other sides of the same question

  1. Using MATLAB through Google Colab

    Can MATLAB commnads be used from Google Colab (cloud-hosted Jupyter)? For instance, I'd like to invoke Risk Management Toolbo…

    Replies 2Latest activity matlab
  2. Can gdb set a breakpoint for an assembly instruction using its address?

    My attempt: apparently this command does not exist, though. Can gdb do something like this?

    Replies 2Latest activity assembly
  3. Can Playwright assertions allow either of two possible text values?

    I'd like to verify that the text contains either one or two: Can this be made to work in Playwright? Could the same thing als…

    Replies 2Latest activity typescript