如何使用 Cocoa 创建临时文件? [英] How do I create a temporary file with Cocoa?

查看:32
本文介绍了如何使用 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

我是否遗漏了一些明显的东西,或者没有内置的方法来做到这一点?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆