P
philip
Here is some lines of code than I wrote. You can copy/paste theis code as
code of form1 in a new project.
My problem is this one :
I try to write in a file a serie of bytes.
BUT some bytes written in file are not the sent bytes.
Copy and paste the following lines to observe my problem.
What can I do to resolve problem ?
Only System.Text.Encoding.ASCII write the same number of bytes, but not the
good bytes.
Someone can help me. Thanks by advance.
Public Class Form1
Dim TextBox1 As New TextBox
Dim TextBox2 As New TextBox
Dim Label1 As New Label
Dim Label2 As New Label
Dim Label3 As New Label
Dim Label4 As New Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Size = New System.Drawing.Size(800, 500)
Label1.Location = New System.Drawing.Size(20, 13)
Label1.Text = "Data to write"
Me.Controls.Add(Label1)
Label2.Location = New System.Drawing.Size(20, 40)
Label2.Text = "Data written"
Me.Controls.Add(Label2)
Label3.Location = New System.Drawing.Size(350, 13)
'Label3.Text = "Data written"
Me.Controls.Add(Label3)
Label4.Location = New System.Drawing.Size(350, 40)
'Label4.Text = "Data written"
Me.Controls.Add(Label4)
TextBox1.Size = New System.Drawing.Size(200, 20)
TextBox1.Location = New System.Drawing.Size(120, 13)
Me.Controls.Add(TextBox1)
TextBox2.Size = New System.Drawing.Size(200, 20)
TextBox2.Location = New System.Drawing.Size(120, 40)
Me.Controls.Add(TextBox2)
Dim button1 As New Button
button1.Text = "BinaryWriter encoding ASCII"
button1.Size = New System.Drawing.Size(200, 20)
button1.Location = New System.Drawing.Size(550, 13)
AddHandler button1.Click, AddressOf Button1_Click
Me.Controls.Add(button1)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Temp As String = "ÿØÿá"
TextBox1.Text = Temp
Label3.Text = "Length to write : " & Temp.Length.ToString & "
octets)"
Dim fullFileName As String = "c:\converted music\test1.jpg"
Dim sw As System.IO.StreamWriter
sw = New System.IO.StreamWriter(fullFileName, False,
System.Text.Encoding.ASCII)
sw.Write(Temp)
sw.Close()
Dim sr As System.IO.StreamReader
sr = New System.IO.StreamReader(fullFileName,
System.Text.Encoding.ASCII)
Do While Not sr.EndOfStream
TextBox2.Text = TextBox2.Text & Chr(sr.Read())
Loop
Label4.Text = "Length written : " & TextBox2.Text.Length.ToString &
" octets)"
sr.Close()
End Sub
End Class
code of form1 in a new project.
My problem is this one :
I try to write in a file a serie of bytes.
BUT some bytes written in file are not the sent bytes.
Copy and paste the following lines to observe my problem.
What can I do to resolve problem ?
Only System.Text.Encoding.ASCII write the same number of bytes, but not the
good bytes.
Someone can help me. Thanks by advance.
Public Class Form1
Dim TextBox1 As New TextBox
Dim TextBox2 As New TextBox
Dim Label1 As New Label
Dim Label2 As New Label
Dim Label3 As New Label
Dim Label4 As New Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Size = New System.Drawing.Size(800, 500)
Label1.Location = New System.Drawing.Size(20, 13)
Label1.Text = "Data to write"
Me.Controls.Add(Label1)
Label2.Location = New System.Drawing.Size(20, 40)
Label2.Text = "Data written"
Me.Controls.Add(Label2)
Label3.Location = New System.Drawing.Size(350, 13)
'Label3.Text = "Data written"
Me.Controls.Add(Label3)
Label4.Location = New System.Drawing.Size(350, 40)
'Label4.Text = "Data written"
Me.Controls.Add(Label4)
TextBox1.Size = New System.Drawing.Size(200, 20)
TextBox1.Location = New System.Drawing.Size(120, 13)
Me.Controls.Add(TextBox1)
TextBox2.Size = New System.Drawing.Size(200, 20)
TextBox2.Location = New System.Drawing.Size(120, 40)
Me.Controls.Add(TextBox2)
Dim button1 As New Button
button1.Text = "BinaryWriter encoding ASCII"
button1.Size = New System.Drawing.Size(200, 20)
button1.Location = New System.Drawing.Size(550, 13)
AddHandler button1.Click, AddressOf Button1_Click
Me.Controls.Add(button1)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Temp As String = "ÿØÿá"
TextBox1.Text = Temp
Label3.Text = "Length to write : " & Temp.Length.ToString & "
octets)"
Dim fullFileName As String = "c:\converted music\test1.jpg"
Dim sw As System.IO.StreamWriter
sw = New System.IO.StreamWriter(fullFileName, False,
System.Text.Encoding.ASCII)
sw.Write(Temp)
sw.Close()
Dim sr As System.IO.StreamReader
sr = New System.IO.StreamReader(fullFileName,
System.Text.Encoding.ASCII)
Do While Not sr.EndOfStream
TextBox2.Text = TextBox2.Text & Chr(sr.Read())
Loop
Label4.Text = "Length written : " & TextBox2.Text.Length.ToString &
" octets)"
sr.Close()
End Sub
End Class