PDA

View Full Version : تبدیل فایل فشرده به باینری



sarairavani
سه شنبه 21 تیر 1390, 11:45 صبح
Private Sub btnCompress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompress.Click
If IO.File.Exists(fdlg.FileName) = False Then
MessageBox.Show("Please specify a valid file (and path) to compress")
Exit Sub
Else
If IO.Directory.Exists(fdlg.InitialDirectory) = False Then
MessageBox.Show("Please provide a destination location")
Exit Sub
End If
End If

' Try

Dim name As String = Path.GetFileName(fdlg.FileName)
Dim source() As Byte = System.IO.File.ReadAllBytes(fdlg.FileName)
Dim compressed() As Byte = ConvertToByteArray(source)
System.IO.File.WriteAllBytes(fdlg.InitialDirectory & "\" & name & ".zip", compressed)
str1 = fdlg.InitialDirectory & "\" & name & ".zip"
'---------------binary
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(str1)
Try
Dim readfile As String = objStreamReader.ReadToEnd()
Dim flStream As FileStream = New FileStream(str1, FileMode.OpenOrCreate, FileAccess.Read)
' Try
Dim bFormatter As BinaryFormatter = New BinaryFormatter
bFormatter.Serialize(flStream, readfile)
Dim a As BinaryFormatter = bFormatter

error :stream was not writable
زمانی به bFormatter.Deserialize(flStream) میزارم error زیر رو میذه

the input stream is not a valid binary format .The starting content (in byte are:1f-88-08-00-00.....)