我在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
答案 0 :(得分: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
答案 1 :(得分: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