Skip to content

Instantly share code, notes, and snippets.

@henryw374
Created August 1, 2025 11:58
Show Gist options
  • Save henryw374/d7396be071f8c507f1ce3dc4549a6105 to your computer and use it in GitHub Desktop.
Save henryw374/d7396be071f8c507f1ce3dc4549a6105 to your computer and use it in GitHub Desktop.
clojure append to zip file
(ns create-zip-archive
(:import (java.net URI)
(java.nio.charset StandardCharsets)
(java.nio.file FileSystem FileSystems Files Paths StandardOpenOption)))
(let [path (Paths/get "test.zip" (make-array String 0))
uri (URI/create (str "jar:" (.toUri path)))]
(with-open [fs (FileSystems/newFileSystem uri {"create" "true"})]
(let [nf (FileSystem/.getPath fs "new.txt" (make-array String 0))]
(with-open [writer (Files/newBufferedWriter nf, StandardCharsets/UTF_8, (into-array [StandardOpenOption/CREATE]))]
(.write writer "hello")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment