Trouble deleting the file

I’m having trouble deleting the file ver.dat in my code on OS X, I can not delete file.
what am I doing wrong?

Thank you,

this code does the following :

  • checks if I am connected to the internet
  • downloads the file
  • read the contents and verify the app version.

if System.Network.IsConnected then

    dim socket1 as new HTTPSocket
    check = new FolderItem("ver.dat")

    call socket1.get("", check, 3)

    e = getfolderitem("ver.dat")
    stream = e.openastextfile

    while not stream.eof
      checkvers = stream.readline

 if e <> nil and e.exists = true then
       if checkvers > vers then
        MsgBox("You have a new version avaiable.")



       end if
 end if


    msgbox("No network connection for you to do research.")

end if

You need to close the stream before attempting to delete the file it represents.

I was not focused on what I was doing.
Thank you Andrew