This language bar is your friend. Select your favorite languages!

Idiom #138 Create temp file

Create a new temporary file on filesystem.

use tempdir::TempDir;
use std::fs::File;
let temp_dir = TempDir::new("prefix")?;
let temp_file = File::open(temp_dir.path().join("file_name"))?;
import std.stdio;
auto f = File.tmpfile();
import "io/ioutil"
tmpfile, err := ioutil.TempFile("", "")
$f = tmpfile();
sysutils
var
  H: THandle;
begin
  H := FileCreate(GetTempFileName);
end.
import tempfile
file = tempfile.TemporaryFile()
require 'tempfile'
file = Tempfile.new('foo') 

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms