Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 641
  • Last Modified:

Read File by blocks

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
databoks
Asked:
databoks
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
nffvrxqgrcfqvvcCommented:
<< I want to use it to compare files.  >>

You may want to also look into hashing if you intend to compare files
0
 
databoksAuthor Commented:
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!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"gule streams"?...can you explain further?
0
 
DansDadUKCommented:
'gule' - perhaps a typo for 'file'? (F-G and U-I being adjacent)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
databoksAuthor Commented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now