Read bytes from file and create a file with the readed bytes

  • Thread starter Thread starter paraidy
  • Start date Start date
P

paraidy

Hi all, as from object i need to read all byte from a file example c:
\myphoto.jpg and recreate the file with another name to another
directory c:\photo\recreatedphoto.jpg can someone write a small
example to do it?
thx a lot men :)
 
You can use these methods to load and save an image.

Dim image1 As Image =
System.Drawing.Image.FromFile("somefilepath.jpg")

image1.Save("someotherfilepath.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

==============
Clay Burch
Syncfusion, Inc.
 
You can use these methods to load and save an image.

Dim image1 As Image =
System.Drawing.Image.FromFile("somefilepath.jpg")

image1.Save("someotherfilepath.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

==============
Clay Burch
Syncfusion, Inc.

Thx for reply, but this should work only with images, i need to read
all bytes and recreate the file from the readed bytes, to make it
compatible with all type of file
 
Thx for reply, but this should work only with images, i need to read
all bytes and recreate the file from the readed bytes, to make it
compatible with all type of file

Are you doing this to just move the file? If so just use
System.IO.File.Move(....) - afaik it's compatible with all file types.

Thanks,

Seth Rowe
 
Are you doing this to just move the file? If so just use
System.IO.File.Move(....) - afaik it's compatible with all file types.

Thanks,

Seth Rowe

Guess I could of given an answer to the original question :-)

How about this?

Dim readStream As Stream = File.Open("C:\Documents and
Settings\srowe\Desktop\pic.jpg", FileMode.Open, FileAccess.Read)
Dim writeStream As Stream = File.Open("C:\Documents and
Settings\srowe\Desktop\pic2.jpg", FileMode.Create, FileAccess.Write)
Dim bw As New BinaryWriter(writeStream)
Dim br As New BinaryReader(readStream)

Do Until br.PeekChar = -1
bw.Write(br.ReadByte)
Loop

Thanks,

Seth Rowe
 
rowe_newsgroups ha scritto:
Guess I could of given an answer to the original question :-)

How about this?

Dim readStream As Stream = File.Open("C:\Documents and
Settings\srowe\Desktop\pic.jpg", FileMode.Open, FileAccess.Read)
Dim writeStream As Stream = File.Open("C:\Documents and
Settings\srowe\Desktop\pic2.jpg", FileMode.Create, FileAccess.Write)
Dim bw As New BinaryWriter(writeStream)
Dim br As New BinaryReader(readStream)

Do Until br.PeekChar = -1
bw.Write(br.ReadByte)
Loop

Thanks,

Seth Rowe

Probably this is what i need, when i comeback to home i test it and
i'll post a reply, Very Thanks :)
 
rowe_newsgroups ha scritto:








Probably this is what i need, when i comeback to home i test it and
i'll post a reply, Very Thanks :)

i have tryied it, it worked with a txt file, but with a .exe of 4 MB
there is an error in this line:
Do Until br.PeekChar = -1
the error is this:
The output char buffer is too small to contain the decoded characters,
encoding 'Unicode (UTF-8)' fallback
'System.Text.DecoderReplacementFallback'.
some help? :(
 
i have tryied it, it worked with a txt file, but with a .exe of 4 MB
there is an error in this line:
Do Until br.PeekChar = -1
the error is this:
The output char buffer is too small to contain the decoded characters,
encoding 'Unicode (UTF-8)' fallback
'System.Text.DecoderReplacementFallback'.
some help? :(

I hate doing it like this, but at the moment my brain can't think of a
way to check for the end of the file without using PeekChar (which
overflows) or using a try catch (slightly inefficient) but hey, free
help doesn't have to be perfect right?

Try this code instead:

Dim readStream As Stream = File.Open("C:\Documents and Settings
\srowe\Desktop\CSDB.Net.exe", FileMode.Open, FileAccess.Read)
Dim writeStream As Stream = File.Open("C:\Documents and
Settings\srowe\Desktop\CSDB.Net2.exe", FileMode.Create,
FileAccess.Write)
Dim bw As New BinaryWriter(writeStream,
System.Text.Encoding.UTF8)
Dim br As New BinaryReader(readStream,
System.Text.Encoding.UTF8)

Do
Try
Dim i As Int32 = br.ReadInt32()
bw.Write(i)
Catch ex As EndOfStreamException
Exit Do
End Try
Loop

Let me know how it works out.

Thanks,

Seth Rowe
 
I hate doing it like this, but at the moment my brain can't think of a
way to check for the end of the file without using PeekChar (which
overflows) or using a try catch (slightly inefficient) but hey, free
help doesn't have to be perfect right?

Try this code instead:

Dim readStream As Stream = File.Open("C:\Documents and Settings
\srowe\Desktop\CSDB.Net.exe", FileMode.Open, FileAccess.Read)
Dim writeStream As Stream = File.Open("C:\Documents and
Settings\srowe\Desktop\CSDB.Net2.exe", FileMode.Create,
FileAccess.Write)
Dim bw As New BinaryWriter(writeStream,
System.Text.Encoding.UTF8)
Dim br As New BinaryReader(readStream,
System.Text.Encoding.UTF8)

Do
Try
Dim i As Int32 = br.ReadInt32()
bw.Write(i)
Catch ex As EndOfStreamException
Exit Do
End Try
Loop

Let me know how it works out.

Thanks,

Seth Rowe

Yes, it worked, Very Thanks!!!
 
Back
Top