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
Solved

Read File by blocks

Posted on 2011-02-20
7
626 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
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.

 
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

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

Suggested Solutions

Title # Comments Views Activity
Install Problem 13 34
Expression Evaluater 3 38
C# class library debugging - Breakpoint will not hit. 8 20
C# Linq - Join two objects into one 3 14
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 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