Created
February 2, 2022 15:29
-
-
Save henryw374/3b0b36278fee945b94321df7913ac524 to your computer and use it in GitHub Desktop.
clojure fileinputstream delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns delete-on-close-fileinput-stream) | |
(defn create-fis [^java.io.File f] | |
(proxy [java.io.FileInputStream] [f] | |
(close [] | |
(try | |
(proxy-super close) | |
(finally | |
(.delete f)))))) | |
(comment | |
(spit "a-file" ["hello"]) | |
(.exists (clojure.java.io/file "a-file")) | |
(slurp "a-file") | |
(def fis (create-fis (clojure.java.io/file "a-file"))) | |
(slurp fis) | |
(.exists (clojure.java.io/file "a-file")) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
already supported by:
Path path = Paths.get(filePath);
InputStream fileStream = Files.newInputStream(path, StandardOpenOption.DELETE_ON_CLOSE);