Jump to content

Secure temporary file: Difference between revisions

New post in addition to an existing minimalistic post
(Secure temporary file in FreeBASIC)
(New post in addition to an existing minimalistic post)
Line 285:
}
}</syntaxhighlight>
 
Alternative example
<syntaxhighlight lang="java">
import java.io.File;
import java.io.IOException;
 
public final class SecureTemporaryFile {
public static void main(String[] args) throws IOException {
// Create a temporary file in the directory D:
File temporaryFile = File.createTempFile("example", ".tmp", new File("D:/"));
// Invoking the following command will cause the file to be deleted when this program exits normally,
// otherwise the file will persist.
temporaryFile.deleteOnExit();
// For security, Java will insert a random number between the file name and the file extension.
if ( temporaryFile.exists() ) {
System.out.println("Temporary file created: " + temporaryFile.getName());
} else {
System.out.println("Temporary file cannot be created: " + temporaryFile.getName());
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
Temporary file created: example12312088502442779987.tmp
</pre>
 
=={{header|Julia}}==
902

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.