当没有指定路径时,Pharo默认保存的文件在哪里?
我目前正在通过Pharo MOOC学习 Pharo ,在讲座“3.8 流概述”中,我们展示了以下用于创建文件的流操作示例:
| stream |
stream := 'hello.txt' asFileReference writeStream.
stream nextPutAll: 'Hello Pharo!'.
stream close.
我在操场上执行了这个代码片段,然后我查看了安装 Pharo 的文件夹,在 Ubuntu 20.04 中的 ~/src/pharolauncher 下,检查文件是否已创建,但它在文件夹或其子文件夹中没有任何位置。
回答
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
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.
- Awesome answer! You were faster than me by one minute or so
- @LeandroCaniglia no need to apologise. I find it to be a fun competition. Sometimes I post first, sometimes you do. Sometimes we provide different answers, sometimes we thing in the same way. In the end the person who asked the question wins 🙂
- Executing 'hello.txt' asFileReference absolutePath and inspecting the results, I got a object with contents "Path / 'home' / 'user' / 'Pharo' / 'images' / 'Pharo Mooc' / 'hello.txt'". Problem solved. Thank you! So there was another folder created under my home folder. I thought everything was saved under the original install folder, and so I did not pay attention to it.