[英]VB.NET code to reverse file contents
I have wrote some code in Visual Basic 6 which reverses the contents of a file, however I have problems converting this code to .NET as VB.NET only reads the text part of the file. 我已经在Visual Basic 6中编写了一些代码来反转文件的内容,但是由于VB.NET仅读取文件的文本部分,因此无法将代码转换为.NET。 Can someone please show me the VB.NET equivalent of this code.
有人可以告诉我该代码的VB.NET等效项。 I believe it will not only help me, but the whole SOF community :).
我相信这不仅会对我有帮助,而且对整个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
Try this 尝试这个
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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.