By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 :)

Feb 1 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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.

Feb 1 '07 #2

P: n/a
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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

Feb 1 '07 #3

P: n/a
On Feb 1, 8:50 am, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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
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

Feb 1 '07 #4

P: n/a
On Feb 1, 9:01 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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

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

Feb 1 '07 #5

P: n/a

rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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
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
Probably this is what i need, when i comeback to home i test it and
i'll post a reply, Very Thanks :)

Feb 1 '07 #6

P: n/a
On 1 Feb, 16:30, "paraidy" <samore...@tiscali.itwrote:
rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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
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

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? :(

Feb 1 '07 #7

P: n/a
On Feb 1, 12:14 pm, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 16:30, "paraidy" <samore...@tiscali.itwrote:
rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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
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
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 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

Feb 1 '07 #8

P: n/a
On 1 Feb, 19:25, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Feb 1, 12:14 pm, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 16:30, "paraidy" <samore...@tiscali.itwrote:
rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tiscali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusion.comwrote:
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
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
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 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!!!

Feb 1 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.