Secure temporary file: Difference between revisions
Content deleted Content added
JVM Windows related bug workaround JDK-4715154 has to taken in account |
|||
Line 94: | Line 94: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
{{incomplete|Clojure|JVM Windows related bug workaround JDK-4715154}} |
|||
<lang Clojure>user=> (doto (java.io.File/createTempFile "pre" ".suff") .deleteOnExit) |
<lang Clojure>user=> (doto (java.io.File/createTempFile "pre" ".suff") .deleteOnExit) |
||
#<File /tmp/pre8116759964152254766.suff></lang> |
#<File /tmp/pre8116759964152254766.suff></lang> |
||
Line 122: | Line 122: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
Follows technique of Java example |
{{incomplete|Groovy|JVM Windows related bug workaround JDK-4715154}}Follows technique of Java example<lang groovy>def file = File.createTempFile( "xxx", ".txt" ) |
||
⚫ | |||
file.deleteOnExit() |
file.deleteOnExit() |
||
println file</lang> |
println file</lang> |
||
Line 162: | Line 161: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
<lang java>import java.io.File; |
{{Incomplete|Java|JVM Windows related bug workaround JDK-4715154}}<lang java>import java.io.File; |
||
try { |
try { |
||
Line 187: | Line 186: | ||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
<lang NetRexx>/* NetRexx */ |
{{incomplete|NetRexx|JVM Windows related bug workaround JDK-4715154}}<lang NetRexx>/* NetRexx */ |
||
options replace format comments java crossref symbols binary |
options replace format comments java crossref symbols binary |
||
Line 363: | Line 362: | ||
irb(main):004:0> f.close |
irb(main):004:0> f.close |
||
=> nil</lang> |
=> nil</lang> |
||
⚫ | |||
<lang scala>import java.io.{File, FileWriter, IOException} |
|||
def writeStringToFile(file: File, data: String, appending: Boolean = false) = |
|||
using(new FileWriter(file, appending))(_.write(data)) |
|||
def using[A <: {def close() : Unit}, B](resource: A)(f: A => B): B = |
|||
⚫ | |||
try f(resource) finally resource.close() |
|||
[[Category:Scala examples needing attention]]Basically same as Java version.<lang scala>import java.io.File |
|||
// Create temp file |
|||
val filename = File.createTempFile("prefix", ".suffix") |
|||
// Delete temp file when program exits |
|||
⚫ | |||
⚫ | |||
⚫ | |||
try { |
|||
⚫ | |||
// Just an example how you can fill a file |
|||
using(new FileWriter(file))(writer => rawDataIter.foreach(line => writer.write(line))) |
|||
scala.compat.Platform.collectGarbage() // JVM Windows related bug workaround JDK-4715154 |
|||
⚫ | |||
⚫ | |||
} catch { |
|||
case e: IOException => println("Running Example failed: ${e.getMessage}") |
|||
⚫ | |||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
<lang sml>val filename = OS.FileSys.tmpName ();</lang> |
<lang sml>val filename = OS.FileSys.tmpName ();</lang> |