如何把WinSock接收的字节数组写TXT文件?
Winsock接收TCP包,是加密的数据,
想把接收的字节数组保存到TXT文件,不知道该如何实现?
[解决办法]
'写TXT文件, 只能写字符串,不能写字节数组 Open App.path & "\test.txt" For Output AS #1 Print #1 Close #1
[解决办法]
你那些‘字节数组’的内容,未必都是在可显示字符的范围啊。
你想以什么样的方式来输出‘文本文件’???
[解决办法]
我猜是这样的:
'将数据转换为16进制字符串
Public Function GetHexFromByte(rData() As Byte) As String
Dim i As Long
Dim strHex As String
Dim j As Integer
For i = 0 To UBound(rData)
j = j + 1
strHex = strHex & Replace(Format(Hex(rData(i)), "@@ "), " ", "0 ")
'If i < UBound(rByteData) Then
strHex = strHex & " "
'End If
Next
GetHexFromByte = strHex
End Function
Public Sub writeDataToFile(ByRef rByteData() As Byte, ByVal vFilename As String)
Dim i As Long
Dim fso As New FileSystemObject
Dim txtStream As TextStream
Set txtStream = fso.OpenTextFile(vFilename, ForAppending, True)
txtStream.Write GetHexFromByte(rByteData)
txtStream.Close
End Sub