Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read File by blocks

Posted on 2011-02-20
7
Medium Priority
?
636 Views
Last Modified: 2012-05-11
I want to read files by blocks.

I want to use it to compare files. This is to build a little Incremental Backup. I have to read the files by blocks.
Compare the values..

Or can anyone give me an example how to do it? Provide me with a better solution if it is possible.
0
Comment
Question by:databoks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 34939627
The standard FileStream allows you to read by blocks.  Just open it up, move the pointer with Seek(), then use Read().

In its simplest form:
Byte[] buffer = new Byte[4096];
            FileStream fs = new FileStream(@"c:\some\path to\a_file.ext", FileMode.Open);
            fs.Seek(someOffsetInBytes, SeekOrigin.Begin);
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();

Open in new window

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 34939957
<< I want to use it to compare files.  >>

You may want to also look into hashing if you intend to compare files
0
 
LVL 8

Author Comment

by:databoks
ID: 34941868
Please give an example ny using gule streams
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34943631
"gule streams"?...can you explain further?
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 34943675
'gule' - perhaps a typo for 'file'? (F-G and U-I being adjacent)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34943721
Hehe...good spot DansDanUK.  =)

Are you asking about comparing two files in blocks now?
...or how to do the Hashing as egl1044 suggests?

Do you need to know WHERE the two files differ?  (read by blocks)
...or just that they are different? (hashing is better)
0
 
LVL 8

Author Comment

by:databoks
ID: 34943742
Sorry - i meant using the FileStream Class., but i can see the example is there.

I have read this through my mobile but couldn't see the code example.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question