(spit "c:/tmp/spit.txt" "012345")
(spit "c:/tmp/spit.txt" "BB")
Results in a file containing: BB345.
Reported via email by cees van Kemenade.
spit with a string argument defaults to opening a FileStream (wrapped in a StreamWriter) in mode FileMode.CreateOrNew. This will work whether or not the file exists. To default to Truncate will fail if the file does not exist. For this reason, I don't want to make it the default. I'm also not sure how to play with tests of file existence versus given file-mode to determine what action to take.
If you know the file exists and want to truncate, call spit with that file mode.
(spit "filename" "test" :file-mode System.IO.FileMode/Truncate)
Correct action is to call spit specifying the file mode:
(spit "c:/tmp/spit.txt" "BB" :file-mode System.IO.FileMode/Truncate)
At the request of the OP, I have decided to reconsider this issue.
Cees suggests the attached code.
Adding to this: change slurp to read the file in non-locking mode.