Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,2 +1,3 @@
|
|||
user=> (doto (java.io.File/createTempFile "pre" ".suff") .deleteOnExit)
|
||||
#<File /tmp/pre8116759964152254766.suff>
|
||||
(let [temp-file (java.io.File/createTempFile "pre" ".suff")]
|
||||
; insert logic here that would use temp-file
|
||||
(.delete temp-file))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
(make-temp-file "prefix")
|
||||
=>
|
||||
"/tmp/prefix25452LPe"
|
||||
|
|
@ -1,3 +1,32 @@
|
|||
import "io/ioutil"
|
||||
package main
|
||||
|
||||
file_obj, err := ioutil.TempFile("", "foo")
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := ioutil.TempFile("", "foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// We need to make sure we remove the file
|
||||
// once it is no longer needed.
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
// … use the file via 'f' …
|
||||
fmt.Fprintln(f, "Using temporary file:", f.Name())
|
||||
f.Seek(0, 0)
|
||||
d, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Wrote and read: %s\n", d)
|
||||
|
||||
// The defer statements above will close and remove the
|
||||
// temporary file here (or on any return of this function).
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
procedure main()
|
||||
write("Creating: ",fName := !open("mktemp","rp"))
|
||||
write(f := open(fName,"w"),"Hello, world")
|
||||
close(f)
|
||||
end
|
||||
|
|
@ -1,14 +1,18 @@
|
|||
import java.io.File
|
||||
import java.io.{File, FileWriter, IOException}
|
||||
|
||||
try {
|
||||
// Create temp file
|
||||
val filename = File.createTempFile("prefix", ".suffix")
|
||||
def writeStringToFile(file: File, data: String, appending: Boolean = false) =
|
||||
using(new FileWriter(file, appending))(_.write(data))
|
||||
|
||||
// Delete temp file when program exits
|
||||
filename.deleteOnExit
|
||||
def using[A <: {def close() : Unit}, B](resource: A)(f: A => B): B =
|
||||
try f(resource) finally resource.close()
|
||||
|
||||
System.out.println(filename)
|
||||
|
||||
} catch {
|
||||
case _: java.io.IOException =>
|
||||
}
|
||||
try {
|
||||
val file = File.createTempFile("_rosetta", ".passwd")
|
||||
// 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
|
||||
file.deleteOnExit()
|
||||
println(file)
|
||||
} catch {
|
||||
case e: IOException => println(s"Running Example failed: ${e.getMessage}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue