2013-07-02 45 views
0

我已經在Visual Basic 6中編寫了一些反轉文件內容的代碼,但是由於VB.NET只讀取文件的文本部分,因此我將該代碼轉換爲.NET時出現問題。有人可以告訴我這個代碼的VB.NET等價物。我相信這不僅會幫助我,還會幫助整個SOF社區:)。用於反轉文件內容的VB.NET代碼

Public Function NeutralizeFile(strFile As String, strOut As String) As Boolean 
On Error GoTo ErrDelete 
Dim File As String 
Open strFile For Binary As #1 
File = Space(LOF(1)) 
Get #1, , File 
Close #1 
File = StrReverse(File) 
Open strOut For Binary As #1 
Put #1, , File 
Close #1 
Kill strFile 
ErrDelete: 
End Function 

回答

0
Public Sub NeutralizeFile(ByVal PathIn As String, ByVal PathOut As String) 
    Try 
     Dim data() As Byte = IO.File.ReadAllBytes(PathIn) 
     Array.Reverse(data) 
     IO.File.WriteAllBytes(PathOut, data) 
    Catch ex As Exception 
     MsgBox("Error") 
    End Try 
End Sub 
0

試試這個

Public Sub NeutralizeFile(strFile As String, strOut As String) 
    Try 
     Dim StreamReader1 As New IO.StreamReader(strFile) 
     Dim StreamWriter1 As New IO.StreamWriter(strOut) 

     StreamWriter1.Write(StrReverse(StreamReader1.ReadToEnd)) 

     StreamReader1.Close() 
     StreamReader1.Dispose() 

     StreamWriter1.Close() 
     StreamWriter1.Dispose() 

     IO.File.Delete(strFile) 
    Catch ex As Exception 
     MsgBox("Error") 
    End Try 
End Sub