Hi All
I need to read a file to an array of bytes (any type of file)
I tried using FileStream and BinaryReader but it doesn't seem to work
Thank you,
Shmuel 8 37127
Shmuel,
You don't really need the BinaryReader if you simply want to read the entire
file into a byte array.
Either of the following works.
' without a BinaryReader
Dim input As New FileStream("myf ile.bin", FileMode.Open)
Dim bytes(CInt(inpu t.Length - 1)) As Byte
input.Read(byte s, 0, CInt(input.Leng th))
' with a BinaryReader
Dim input As New FileStream("myf ile.bin", FileMode.Open)
Dim reader As New BinaryReader(in put)
Dim bytes() As Byte
bytes = reader.ReadByte s(CInt(input.Le ngth))
Hope this helps
Jay
"S Shulman" <sm*******@hotm ail.com> wrote in message
news:OY******** ******@TK2MSFTN GP11.phx.gbl... Hi All
I need to read a file to an array of bytes (any type of file) I tried using FileStream and BinaryReader but it doesn't seem to work
Thank you, Shmuel
Jay,
* "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> scripsit: Either of the following works.
' without a BinaryReader Dim input As New FileStream("myf ile.bin", FileMode.Open) Dim bytes(CInt(inpu t.Length - 1)) As Byte input.Read(byte s, 0, CInt(input.Leng th))
Attention!
<URL:http://www.yoda.arachs ys.com/csharp/readbinary.html >
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried, Attention!
Careful! ;-)
I was thinking of mentioning you really should "block" the reads, but didn't
consider it important enough in my initial answer...
M S Herfried K. Wagner
BTW: What is the "M S" in your signature? I'm on the Marklin Mailing List,
and MS refers to Mobile Station on there, not Microsoft...
Jay
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2o******** ****@uni-berlin.de... Jay,
* "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> scripsit: Either of the following works.
' without a BinaryReader Dim input As New FileStream("myf ile.bin", FileMode.Open) Dim bytes(CInt(inpu t.Length - 1)) As Byte input.Read(byte s, 0, CInt(input.Leng th))
Attention!
<URL:http://www.yoda.arachs ys.com/csharp/readbinary.html >
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jay,
* "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> scripsit: Attention!
Careful! ;-)
I was thinking of mentioning you really should "block" the reads, but didn't consider it important enough in my initial answer...
ACK. M S Herfried K. Wagner
BTW: What is the "M S" in your signature? I'm on the Marklin Mailing List, and MS refers to Mobile Station on there, not Microsoft...
;-) -- it stands for "Microsoft" . "MSFT" would not fit into the signature.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Just learning VB.Net and was interested in the blocking you mentioned. If I
understand correctly, the following is not guaranteed to read all the bytes:
dim fs as FileStream(myfi lename, filemode.Open)
dim byt() as byte
dim r as binaryreader(fs )
byt = r.ReadBytes(fs. Length)
Do I need to use blocking to insure I get all the file into byt? I didn't
see this mentioned in the VB.Net Documentation on the binary reader class.
"Jay B. Harlow [MVP - Outlook]" wrote: Herfried,
Attention!
Careful! ;-)
I was thinking of mentioning you really should "block" the reads, but didn't consider it important enough in my initial answer...
M S Herfried K. Wagner
BTW: What is the "M S" in your signature? I'm on the Marklin Mailing List, and MS refers to Mobile Station on there, not Microsoft...
Jay
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message news:2o******** ****@uni-berlin.de... Jay,
* "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> scripsit: Either of the following works.
' without a BinaryReader Dim input As New FileStream("myf ile.bin", FileMode.Open) Dim bytes(CInt(inpu t.Length - 1)) As Byte input.Read(byte s, 0, CInt(input.Leng th))
Attention!
<URL:http://www.yoda.arachs ys.com/csharp/readbinary.html >
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Dennis,
Reading Jon's site (the link Herfried gave) you should block (read in
chunks) the read, when using Stream.Read, at the very least you should check
the return value from Stream.Read to ensure that you read what you expected
to read!
BinaryReader.Re adBytes does not allow you to block the read, I would expect
internally it uses code similar to Jon's code.
Hope this helps
Jay
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:26******** *************** ***********@mic rosoft.com... Just learning VB.Net and was interested in the blocking you mentioned. If
I understand correctly, the following is not guaranteed to read all the
bytes: dim fs as FileStream(myfi lename, filemode.Open) dim byt() as byte dim r as binaryreader(fs ) byt = r.ReadBytes(fs. Length)
Do I need to use blocking to insure I get all the file into byt? I didn't see this mentioned in the VB.Net Documentation on the binary reader class.
"Jay B. Harlow [MVP - Outlook]" wrote:
Herfried,
Attention!
Careful! ;-)
I was thinking of mentioning you really should "block" the reads, but
didn't consider it important enough in my initial answer...
M S Herfried K. Wagner
BTW: What is the "M S" in your signature? I'm on the Marklin Mailing
List, and MS refers to Mobile Station on there, not Microsoft...
Jay
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message news:2o******** ****@uni-berlin.de... Jay,
* "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> scripsit: > Either of the following works. > > ' without a BinaryReader > Dim input As New FileStream("myf ile.bin", FileMode.Open) > Dim bytes(CInt(inpu t.Length - 1)) As Byte > input.Read(byte s, 0, CInt(input.Leng th))
Attention!
<URL:http://www.yoda.arachs ys.com/csharp/readbinary.html >
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:O6******** *****@TK2MSFTNG P11.phx.gbl... M S Herfried K. Wagner
BTW: What is the "M S" in your signature? I'm on the Marklin Mailing List, and MS refers to Mobile Station on there, not Microsoft...
Look at the left-hand side of all three lines of his .sig: M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
In case you're still not getting it, try this:
M S M V P V B This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
I have a PHP script that would read in a binary file and display it as if it
were <img src>, how would you do that w/o changing the header's MIME type?
The entire file does not need to be changed.
Thanks
Phil
|
by: DrewM |
last post by:
I'm using ASP to generate an RTF (rich text) file, via the FSO. No
problems with text, but when it comes to inserting images, the files
have to be embedded as either binary or hex.
Try as I might, I can't get binary to work (Word b0rks trying to open
the resulting file). When I create a simple RTF in Wordpad and then view
its source, Wordpad seems to be embedding the image as hex.
Does anyone have a suggestion as to how I could read an...
|
by: Pete |
last post by:
Hi
Could someone kindly help with the C# equivilent of the following 4 lines
of C code. I'm *really* struggling with this.
( Colours.dat contains 300 RGB values )
COLORREF Colours;
|
by: Quinn |
last post by:
Hi all,
I have some binary files in the following format:
text line 1
text line 2
....
text line N
end of text
single in binary 1 single in binary 2 single N EOF
|
by: Matrixinline |
last post by:
Hi All
Here is my problem I am using a Unicode project
and I tried to read the File like
sPath = LPCTSTR;
FILE* oFp = _tfopen(sPath,L"r");
while(!feof(oFp))
| |
by: kowndinya |
last post by:
Hello,
i want to read values from a binary file in VisualBasic 6.0
Initially i want to read only header of this binary file. I know this structure for this header. It is 100 bytes long and consists of
9 variables of Integer: Signed 32-bit integer (4 bytes) and
8 variables of Double: Signed 64-bit IEEE double-precision floating point number (8 bytes).
when i tried to assign integer and double data type for these variables i am...
|
by: tulasisridhar |
last post by:
Hi All,
I have binary file created in Unix
I now need to read it using VB.net and doo some procesing.
There is some conversion between bigendian and little endians.
I know the structure of the file of the binary file..... Any suggestions
|
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...
|
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
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...
| |