Secure temporary file: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Change to use more secure method)
Line 395: Line 395:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1.2
<syntaxhighlight lang="kotlin">import kotlin.io.path.createTempFile
import kotlin.io.path.deleteExisting


fun main() {
import java.io.File
val tempFilePath = createTempFile("example", ".tmp")

println("Temporary file created: $tempFilePath")
fun main(args: Array<String>) {
tempFilePath.deleteExisting()
try {
val tf = File.createTempFile("temp", ".tmp")
println(tf.absolutePath)
tf.delete()
}
catch (ex: Exception) {
println(ex.message)
}
}</syntaxhighlight>
}</syntaxhighlight>
Sample output (Ubuntu v14.04):
Sample output:
{{out}}
{{out}}
<pre>
<pre>
Temporary file created: /tmp/example14437465325231438926.tmp
/tmp/temp1551492276377305257.tmp
</pre>
</pre>