I get this error when trying to read from a file that I have written using the second block of code (Sub WriteToFile()) :
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'.
I can't figure out what is happening.. What I am trying to do is : write a list of doubles and read a list of doubles ... and I don't know why I am getting the error in the line 17... What output char buffer?
What can I do to fix this ?
thank you Realolman
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'.
I can't figure out what is happening.. What I am trying to do is : write a list of doubles and read a list of doubles ... and I don't know why I am getting the error in the line 17... What output char buffer?
VB.NET:
Private Sub btnReadFile_Click_1(sender As Object, e As EventArgs) Handles btnReadFile.Click
Dim strSeconds As String
txtReadFile.Text = ""
txtFileName.Text = ""
My.Computer.FileSystem.CurrentDirectory = "C:\Users\Wayne\Desktop\furnace monitoring files"
OpenFileDialog1.Title = "Please Select File"
OpenFileDialog1.Filter = "fmf|*.fmf"
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
txtFileName.Text = OpenFileDialog1.SafeFileName
My.Computer.FileSystem.CurrentDirectory = "C:\Users\Wayne\Desktop\furnace monitoring files"
Dim fsr As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim breader As New BinaryReader(fsr)
CC = 3
'Try
'Catch ex As IOException
Do While breader.PeekChar > -1
readFileSeconds(CC) = breader.ReadDouble
txtReadFile.Text = txtReadFile.Text & vbCrLf & strSeconds & vbCrLf
readFileSeconds(CC) = CDbl(strSeconds)
CC = CC + 1
Loop
'End Try
breader.Close()
breader.Dispose()
fsr.Close()
fsr.Dispose()
End If
End Sub
Sub WriteToFile()
Dim myDate As String
Dim fileName As String
btnSaveToFile.Enabled = False
btnSaveToFile.Text = "saving to file"
myDate = Now.ToString("ddMMMyy HH mm.ss")
fileName = myDate & ".fmf"
txtStartTime.Text = myDate
My.Computer.FileSystem.CurrentDirectory = "C:\Users\Wayne\Desktop\furnace monitoring files"
Dim fs As New FileStream(fileName, FileMode.Append, FileAccess.Write)
Dim bwriter As New BinaryWriter(fs)
For c = 3 To 12
bwriter.Write(timeSeconds(c)) ' timing of event
tbxWritten.Text = tbxWritten.Text & vbCrLf & timeSeconds(c)
Next
bwriter.Close()
fs.Close()
'LastState(CC) = intState
btnSaveToFile.Enabled = True
btnSaveToFile.Text = "save to file"
End Sub
VB.NET:
thank you Realolman