나는 어떤 일이 일어나고 있는지 잘 모르겠습니다. 나는 모든 코드를 변경 생각하지 않지만, 어떤 이유로 나는 파일의 바이트를 읽어 FileStream 객체를 사용 후 반환 된 문자 사이에 공백을 얻고있다 : 나는 _maxBytes 설정 한vb.net 바이트를 디코딩 한 후 파일 스트림에 공백이 있음
'Turn off Raise Events until after change is checked
fsw.EnableRaisingEvents = False
'read from current seek position to end of file
Dim bytesRead(_maxBytes) As Byte
Dim fs As New FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
If (fs.Length > _maxBytes) Then
previousSeekPosition = fs.Length - _maxBytes
End If
previousSeekPosition = fs.Seek(previousSeekPosition, SeekOrigin.Begin)
Dim numBytes = fs.Read(bytesRead, 0, _maxBytes)
fs.Close()
previousSeekPosition += numBytes
Dim sb As New StringBuilder()
For i = 0 To numBytes - 1
sb.Append(bytesRead(i))
Next
'Raise the event to show data
If Not blnFirstRun Then
RaiseEvent MoreData(Me, Encoding.ASCII.GetString(bytesRead, 0, _maxBytes), _filename, _fileDescription)
Else
blnFirstRun = False
End If
'Check the changes against the alerts
AlertChange(Encoding.ASCII.GetString(bytesRead, 0, _maxBytes))
'Turn Raise Events back on
fsw.EnableRaisingEvents = True
을 기본적으로 파일 변경이있을 때마다 마지막으로 알려진 읽기 위치에서 파일을 읽습니다 (Linux 테일이하는 것과 유사).
파일을 테스트 한 결과 잘 작동하는 것으로 보입니다. 웬일인지, 그것은 더 이상 일하고 싶지 않다. do not는 를 생각한다 나는 무엇이라도 바꿨다 - 그러나 지금 지금 공간과 함께 변화를 돌려 준다. 예를 들어
:
난에 '9999'을 추가 한 파일이 있습니다. Encoding.ASCII.GetString 루틴을 실행하면 '9 9 9 9'와 같이 나타납니다.
나는 벽에 맞서 머리를 때리는 것처럼 느껴진다. 바라기를 누군가는 응답을 빨리 알고있다.
언뜻보기에 필자는 파일에 "9999"를 쓴 것이 UTF-16 인코딩을 사용했음을 제안합니다. 독립적 인 견해를 위해 16 진수 편집기로 파일을 검사해야합니다. –
오 ~ 쓰레기 ... 그래서 간단합니다. 예. encoding.unicode.getstring으로 변경되었습니다. 정상적으로 작동합니다. 대답을 만들어 주시겠습니까? – Andrew