当没有指定路径时,Pharo 默认保存的文件在哪里?

kle*_*ite 2 smalltalk file save pharo

我目前正在通过Pharo MOOC学习 Pharo ,在讲座“3.8 流概述”中,我们展示了以下用于创建文件的流操作示例:

| stream |
stream := 'hello.txt' asFileReference writeStream.
stream nextPutAll: 'Hello Pharo!'.
stream close.
Run Code Online (Sandbox Code Playgroud)

我在操场上执行了这个代码片段,然后我查看了安装 Pharo 的文件夹,在 Ubuntu 20.04 中的 ~/src/pharolauncher 下,检查文件是否已创建,但它在文件夹或其子文件夹中没有任何位置。

Lea*_*lia 7

You have a relative path and would like to convert it to absolute, right?

OK. The key part of your code is

'hello.txt' asFileReference
Run Code Online (Sandbox Code Playgroud)

If you inspect this object you will see its class is, not surprisingly, FileReference. Browse the class. Find some selector containing the word 'absolute' or 'Absolute'. The one that looks promising is #absolutePath. Give it a try.

  • 很棒的答案!你比我快了一分钟左右 (3认同)
  • @LeandroCaniglia 无需道歉。我发现这是一场有趣的比赛。有时是我先发帖,有时是你先发帖。有时我们提供不同的答案,有时我们以相同的方式思考。最后提出问题的人获胜:) (3认同)
  • 执行 'hello.txt' asFileReference AbsolutePath 并检查结果,我得到了一个内容为“Path / 'home' / 'user' / 'Pharo' / 'images' / 'Pharo Mooc' / 'hello.txt'”的对象。问题解决了。谢谢你!所以在我的主文件夹下创建了另一个文件夹。我以为所有的东西都保存在原来的安装文件夹下,所以我没有注意它。 (2认同)