Solved

Read File by blocks

Posted on 2011-02-20
7
619 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
Comment Utility
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
Comment Utility
<< 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
Comment Utility
Please give an example ny using gule streams
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 85

Expert Comment

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

Expert Comment

by:DansDadUK
Comment Utility
'gule' - perhaps a typo for 'file'? (F-G and U-I being adjacent)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

11 Experts available now in Live!

Get 1:1 Help Now