如何用Cocoa创建一个临时文件? [英] How do I create a temporary file with Cocoa?
本文介绍了如何用Cocoa创建一个临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
多年前,当我使用C#,我可以很容易地创建一个临时文件,并得到它的名称与此功能:
Years ago when I was working with C# I could easily create a temporary file and get its name with this function:
Path.GetTempFileName();
此函数将在临时目录中创建一个具有唯一名称的文件,并返回完整路径文件。
This function would create a file with a unique name in the temporary directory and return the full path to that file.
在Cocoa API中,我能找到的最接近的是:
In the Cocoa API's, the closest thing I can find is:
NSTemporaryDirectory
我缺少明显的东西或没有内置的方法来做到这一点? p>
Am I missing something obvious or is there no built in way to do this?
推荐答案
一个安全的方法是使用 mkstemp(3)。
A safe way is to use mkstemp(3).
这篇关于如何用Cocoa创建一个临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文