0

我在 Visual Basic 6 中编写了一些代码来反转文件的内容,但是我在将此代码转换为 .NET 时遇到问题,因为 VB.NET 仅读取文件的文本部分。有人可以给我看一下这段代码的 VB.NET 等价物吗?我相信它不仅会帮助我,还会帮助整个 SOF 社区:)。

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
4

2 回答 2

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
于 2013-07-02T12:17:50.980 回答
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
于 2013-07-02T13:27:20.973 回答