Close access not necessary, because you've never opened a file for access to begin with.
This will produce an -39 error on my machine if the file has NO content.
'read' is a Standard Additions command that has nothing to do with TextWrangler, and canonical usage these days is to place osax calls outside of application tell-blocks (as annoying as that is).
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on writeFile(srcData, targetFile, startPosition, dataType)
try
set fileRef to open for access targetFile with write permission
if startPosition = 0 then
set eof of fileRef to 0
end if
write srcData to fileRef as dataType starting at startPosition
close access fileRef
on error eMsg number eNum
try
close access fileRef
end try
error eMsg & return & "Error Number: " & eNum
end try
end writeFile
-------------------------------------------------------------------------------------------
--» MAIN
-------------------------------------------------------------------------------------------
try
set srcFile to choose file
set srcData to read srcFile as «class utf8»
set hdrData to "<HEADER CODE>" & return
set destFile to choose file
set destData to hdrData & srcData
writeFile(destData, destFile, 0, «class utf8»)
on error eMsg number eNum
set e to eMsg & return & return & "Num: " & eNum
tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
if button returned of dDlg = "Copy" then set the clipboard to e
end try
-------------------------------------------------------------------------------------------
You don't need to read with a delimiter unless it is neither CR or LF.
If you give us a little more information we might be able to help streamline things a bit.