468,771 Members | 1,922 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

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

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
8 1934
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
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
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
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

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
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
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
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.

Similar topics

18 posts views Thread by jas | last post: by
5 posts views Thread by Sumana | last post: by
4 posts views Thread by ad | last post: by
3 posts views Thread by phwashington | last post: by
2 posts views Thread by Kevin Ar18 | last post: by
9 posts views Thread by vineeth | last post: by
3 posts views Thread by =?Utf-8?B?VHJlY2l1cw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.