Logo

Programming-Idioms

  • Java

Idiom #138 Create temp file

Create a new temporary file on the filesystem.

import java.io.File;
File tempFile = File.createTempFile("prefix-", "-suffix");
tempFile.deleteOnExit();

This will create a File with a name like "prefix-6340763779352094442-suffix"
#include <stdlib.h>
const char tmpl[] = "XXXXXX.tmp";
int fd = mkstemp(tmpl);

Template must contain six X characters that will be modified by mkstemp

New implementation...
< >
programming-idioms.org