进程无法访问文件[VB.Net]

进程无法访问文件[VB.Net],vb.net,Vb.net,我试图保存一个文件,然后加密并删除临时未加密的文件。这是我的加密子,错误行出现在最后一行 Sub EncryptFile(ByVal sInputFilename As String, _ ByVal sOutputFilename As String, _ ByVal sKey As String) Dim fsInput As New FileStream(sInputFilename, _

我试图保存一个文件,然后加密并删除临时未加密的文件。这是我的加密子,错误行出现在最后一行

Sub EncryptFile(ByVal sInputFilename As String, _
              ByVal sOutputFilename As String, _
              ByVal sKey As String)

    Dim fsInput As New FileStream(sInputFilename, _
                                FileMode.Open, FileAccess.Read)
    Dim fsEncrypted As New FileStream(sOutputFilename, _
                                FileMode.Create, FileAccess.Write)

    Dim DES As New DESCryptoServiceProvider()

    'Set secret key for DES algorithm.
    'A 64-bit key and an IV are required for this provider.
    DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)

    'Set the initialization vector.
    DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)

    'Create the DES encryptor from this instance.
    Dim desencrypt As ICryptoTransform = DES.CreateEncryptor()
    'Create the crypto stream that transforms the file stream by using DES encryption.
    Dim cryptostream As New CryptoStream(fsEncrypted, _
                                        desencrypt, _
                                        CryptoStreamMode.Write)

    'Read the file text to the byte array.
    Dim bytearrayinput(fsInput.Length - 1) As Byte
    fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
    'Write out the DES encrypted file.
    cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
    cryptostream.Close()
    System.IO.File.Delete(sInputFilename)
End Sub
有人能帮我解决这个问题吗?我不知道我做错了什么。

System.IO.File.Delete(sInputFilename)
之前使用
fsInput.Close()


希望这有帮助

您是否尝试过在
System.IO.File.Delete(sInputFilename)
之前发出
fsInput.Close()