473,778 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\recrea tedphoto.jpg can someone write a small
example to do it?
thx a lot men :)

Feb 1 '07 #1
8 2234
You can use these methods to load and save an image.

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

image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.Jpeg)

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

Feb 1 '07 #2
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.

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

image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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...@tisc ali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.
Dim image1 As Image =
System.Drawing. Image.FromFile( "somefilepath.j pg")
image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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_newsgroup s" <rowe_em...@yah oo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.
Dim image1 As Image =
System.Drawing. Image.FromFile( "somefilepath.j pg")
image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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:\D ocuments and
Settings\srowe\ Desktop\pic.jpg ", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\pic2.jp g", FileMode.Create , FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream)
Dim br As New BinaryReader(re adStream)

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

Thanks,

Seth Rowe

Feb 1 '07 #5

rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.
Dim image1 As Image =
System.Drawing. Image.FromFile( "somefilepath.j pg")
image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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:\D ocuments and
Settings\srowe\ Desktop\pic.jpg ", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\pic2.jp g", FileMode.Create , FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream)
Dim br As New BinaryReader(re adStream)

Do Until br.PeekChar = -1
bw.Write(br.Rea dByte)
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...@tisc ali.itwrote:
rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.
Dim image1 As Image =
System.Drawing. Image.FromFile( "somefilepath.j pg")
image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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:\D ocuments and
Settings\srowe\ Desktop\pic.jpg ", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\pic2.jp g", FileMode.Create , FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream)
Dim br As New BinaryReader(re adStream)
Do Until br.PeekChar = -1
bw.Write(br.Rea dByte)
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.De coderReplacemen tFallback'.
some help? :(

Feb 1 '07 #7
On Feb 1, 12:14 pm, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 16:30, "paraidy" <samore...@tisc ali.itwrote:
rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.
Dim image1 As Image =
System.Drawing. Image.FromFile( "somefilepath.j pg")
image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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:\D ocuments and
Settings\srowe\ Desktop\pic.jpg ", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\pic2.jp g", FileMode.Create , FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream)
Dim br As New BinaryReader(re adStream)
Do Until br.PeekChar = -1
bw.Write(br.Rea dByte)
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.De coderReplacemen tFallback'.
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:\D ocuments and Settings
\srowe\Desktop\ CSDB.Net.exe", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\CSDB.Ne t2.exe", FileMode.Create ,
FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream,
System.Text.Enc oding.UTF8)
Dim br As New BinaryReader(re adStream,
System.Text.Enc oding.UTF8)

Do
Try
Dim i As Int32 = br.ReadInt32()
bw.Write(i)
Catch ex As EndOfStreamExce ption
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_newsgroup s" <rowe_em...@yah oo.comwrote:
On Feb 1, 12:14 pm, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 16:30, "paraidy" <samore...@tisc ali.itwrote:
rowe_newsgroups ha scritto:
On Feb 1, 9:01 am, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
On Feb 1, 8:50 am, "paraidy" <samore...@tisc ali.itwrote:
On 1 Feb, 14:04, "ClayB" <c...@syncfusio n.comwrote:
You can use these methods to load and save an image.
Dim image1 As Image =
System.Drawing. Image.FromFile( "somefilepath.j pg")
image1.Save("so meotherfilepath .jpg",
System.Drawing. Imaging.ImageFo rmat.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:\D ocuments and
Settings\srowe\ Desktop\pic.jpg ", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\pic2.jp g", FileMode.Create , FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream)
Dim br As New BinaryReader(re adStream)
Do Until br.PeekChar = -1
bw.Write(br.Rea dByte)
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.De coderReplacemen tFallback'.
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:\D ocuments and Settings
\srowe\Desktop\ CSDB.Net.exe", FileMode.Open, FileAccess.Read )
Dim writeStream As Stream = File.Open("C:\D ocuments and
Settings\srowe\ Desktop\CSDB.Ne t2.exe", FileMode.Create ,
FileAccess.Writ e)
Dim bw As New BinaryWriter(wr iteStream,
System.Text.Enc oding.UTF8)
Dim br As New BinaryReader(re adStream,
System.Text.Enc oding.UTF8)

Do
Try
Dim i As Int32 = br.ReadInt32()
bw.Write(i)
Catch ex As EndOfStreamExce ption
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22830
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F: operator delete(void*) (vg_replace_malloc.c:156) ==11604== by 0x804A1BA: __gnu_cxx::new_allocator<Foo>::deallocate(Foo*, unsigned) (new_allocator.h:86) ==11604== by 0x8049C08: std::_Vector_base<Foo, std::allocator<Foo> >::_M_deallocate(Foo*,...
18
4893
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
5
5119
by: Sumana | last post by:
Hi All, We developed our project on VC++.Net console application to create image of disk and to write the image We are having problem with reading and writing the sector beyond 6GB Disk or Partition we are using ReadFile , WriteFile and setFilePointerEx to read and write the sectors and we are reading/writing 102400 sectors together, even we have reduced the sectors still it is not able to read or write, our program is working fine...
4
14664
by: ad | last post by:
Hi, I have a file (c:\myFile.zip) in the Server. How can I read the file into a Stream?
3
3241
by: phwashington | last post by:
I am new to C++ and have a data file I want to read, which was stored in binary. I have looked at the data with a hex editor and it appears to be correct. Whenever I try to read it though as an integer it returns the 8bit integer values. I can convert these to hex and they match up with what I am seeing in the data file. I guess what I need to do somehow buffer these inputs and then read them as floats, but I am not sure how to do...
2
5454
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\zipfile.py", line 491, in read bytes = self.fp.read(zinfo.compress_size) OverflowError: long it too large to...
9
3850
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data = file.read() print "bytes read ", len(data) ---
3
11529
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I'm creating an application that will read emails from GMail, using the System.Net.Sockets.TcpClient and POP protocol. However, I am having a problem with my SslStream. After I create the TcpClient, I create my SslStream... stream = new System.Net.Security.SslStream(tcpclient.GetStream()...);
4
4263
by: skunapareddy | last post by:
I am needing to read a blob from database and pass it to another java program. I researched internet and found a program that reads a file on the client pc and gives bytes, but when I modified the code to read a blob from DB I am not having any luck, I am running this java programs using JDEVELOPER. Can anyone please give me some help? The code is as follows: ... private static byte getBytesFromBlob(Blob blob) throws Exception { ...
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.