new_tmp
Description:
[ Version ( since = "2.32" ) ]
public static File new_tmp (string? tmpl, out FileIOStream iostream) throws Error
public static File new_tmp (string? tmpl, out FileIOStream iostream) throws Error
Opens a file in the preferred directory for temporary files (as returned by get_tmp_dir) and returns a File and FileIOStream pointing to it.
tmpl
should be a string in the GLib file name encoding containing a sequence of six 'X' characters, and containing no directory
components. If it is null, a default template is used.
Unlike the other File constructors, this will return null if a temporary file could not be created.
Example: Temporary files:
public static int main (string[] args) {
try {
FileIOStream iostream;
File file = File.new_tmp ("tpl-XXXXXX.txt", out iostream);
print ("tmp file name: %s\n", file.get_path ());
OutputStream ostream = iostream.output_stream;
DataOutputStream dostream = new DataOutputStream (ostream);
dostream.put_string ("my tmp data\n");
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.File.new_tmp.vala
Parameters:
tmpl |
Template for the file name, as in open_tmp, or null for a default template |
iostream |
on return, a FileIOStream for the created file |