0
因此,我目前正在ping一個smtp來檢查IP是否正常工作,然後用我的發現寫入一個文本文件,所有內容都是從一件事開始工作。當它寫入文本文件時,它會執行加載和我不想要/需要的換行負載。寫入導致不必要的換行符的文本文件
IO.File.AppendAllText(SummaryfilePath, Now.ToLongTimeString & " - " & URL + vbNewLine)
Dim request As SmtpClient = New SmtpClient(URL)
Dim address As String()
address = request.Host.Split(":")
request.Host = address(1)
request.Host = request.Host.TrimStart("/")
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect(request.Host, request.Port)
Try
Dim networkStream As Sockets.NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
IO.File.AppendAllText(SummaryfilePath, Now.ToLongTimeString & " - " & returndata & vbNewLine & vbNewLine)
'Using sw As StreamWriter = File.AppendText(SummaryfilePath)
' sw.WriteLine(Now.ToLongTimeString & " - " & returndata & vbNewLine & vbNewLine)
' sw.WriteLine("")
'End Using
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If
Catch ex As Exception
IO.File.AppendAllText(SummaryfilePath, Now.ToLongTimeString & " - ERROR! " & ex.Message + vbNewLine & vbNewLine)
End Try
End If
這是代碼行其寫入文本文件,之後它在文本文件中至少50/60換行做下一個脈衝之前。
IO.File.AppendAllText(SummaryfilePath, Now.ToLongTimeString & " - " & returndata & vbNewLine & vbNewLine)
我已經嘗試過使用一個streamwriter,但它也做同樣的事情。我已經研究了什麼是返程數據庫,看看它是否會帶來數百萬次類似的休息時間,事實並非如此。任何幫助將是驚人的。
你知道'vbNewLine'是增加換行符,對吧? –
@Nadeem_MK - 是的,我知道,它假設增加2行。當我打開文本文件時,我有大約50/60。刪除VbNewLine不能解決這個問題。 – Nick
查閱有關Encoding.ASCII.GetString的文檔https://msdn.microsoft.com/zh-cn/library/744y86tc(v=vs.110).aspx – Steve