473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

read the content of binary files till the end of file

30
hi every one,
can u tel me please that how i can read the binary file till the end of file.......
Feb 28 '08 #1
7 1616
kenobewan
4,871 Expert 4TB
What method are you using and do you receive an error?
Feb 28 '08 #2
If you want to read all the bytes into an array, you can do this

Expand|Select|Wrap|Line Numbers
  1. string filePath = //some file path
  2. using(FileStream fs = new FileStream(filePath, FileMode.Open))
  3. {
  4.     using(BinaryReader br = new BinaryReader(fs))
  5.     {
  6.         byte[] buffer = br.ReadBytes((int)br.BaseStream.Length);
  7.     }
  8. }
  9.  
Hope this helps
Feb 28 '08 #3
Plater
7,872 Expert 4TB
A regular FileStream will work for the reading in of the bytes.
BinaryReader is just used to implicitly create numerical values out of the data bytes.
Feb 28 '08 #4
A regular FileStream will work for the reading in of the bytes.
BinaryReader is just used to implicitly create numerical values out of the data bytes.
He is correct, you don't need the BinaryReader. You can simply do:

Expand|Select|Wrap|Line Numbers
  1. using(FileStream fs = new FileStream(filePath, FileMode.Open))
  2. {
  3.     byte[] buffer = new byte[fs.Length];
  4.     fs.Read(buffer, 0, fs.Length);
  5. }
  6.  
Feb 28 '08 #5
balabaster
797 Expert 512MB
He is correct, you don't need the BinaryReader. You can simply do:

Expand|Select|Wrap|Line Numbers
  1. using(FileStream fs = new FileStream(filePath, FileMode.Open))
  2. {
  3. byte[] buffer = new byte[fs.Length];
  4. fs.Read(buffer, 0, fs.Length);
  5. }
  6.  
To complicate things a little less could he not use:

byte[] buffer = System.IO.File.ReadAllBytes("C:\MyFile.exe");

?
Feb 28 '08 #6
I have written file handling code here :
just copy &paste;
[Link Removed]
Mar 3 '08 #7
MMcCarthy
14,534 Expert Mod 8TB
@ Rajeshshewale

If you wish to submit code please submit it in the thread and not using a link.

ADMIN
Mar 3 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: nandha | last post by:
H I have a doubt in VC++ regarding file reading and displaying in the GUI (Dialog I have a binary file, which contains several piece of information , i have to read the information continuously...
5
by: AC [MVP MCMS] | last post by:
Any pointers on how to (1) read a Base64 encoded string from a text file and (2) write it to a binary file? I have a ton of files that are being generated from a legacy system. Each file...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
11
by: jean-jeanot | last post by:
I can access to a file with the command: file_obj = open ( " D:\My documents\Textfile.txt",'r') When I now try to read a file with the following command: file_obj = open ("D:\My...
2
by: D`Jinn Deegee | last post by:
I have 5 html files say file1.html file2.html : : file5.html Now I have another html file (main.html) where I want to use 1 html
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
9
by: Matrixinline | last post by:
Hi All, Here is the problem char* memblock; std::ifstream file(sFileName, ios::in|ios::binary); if (file.is_open()) { size = file.tellg();
9
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 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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...

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.