Solved

Read File by blocks

Posted on 2011-02-20
7
621 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
7 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now