Compare two files : FileStream « File Stream « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » File Stream » FileStreamScreenshots 
Compare two files

/*
C# A Beginner's Guide
By Schildt

Publisher: Osborne McGraw-Hill
ISBN: 0072133295
*/
/*   
   Project 11-1 
 
   Compare two files. 
 
   To use this program, specify the names   
   of the files to be compared on the command line. 
 
   For example: 
       CompFile FIRST.TXT SECOND.TXT  
*/  
  
using System; 
using System.IO;  
  
public class CompFiles {  
  public static void Main(string[] args) {  
    int i=0, j=0;  
    FileStream f1;  
    FileStream f2;  
  
    try {  
      // open first file 
      try {  
        f1 = new FileStream(args[0], FileMode.Open);  
      catch(FileNotFoundException exc) {  
        Console.WriteLine(exc.Message);  
        return;  
      }  
  
      // open second file  
      try {  
        f2 = new FileStream(args[1], FileMode.Open);  
      catch(FileNotFoundException exc) {  
        Console.WriteLine(exc.Message);  
        return;  
      }  
    catch(IndexOutOfRangeException exc) {  
      Console.WriteLine(exc.Message + "\nUsage: CompFile f1 f2");  
      return;  
    }  
  
    // Compare files  
    try {  
      do {  
        i = f1.ReadByte();  
        j = f2.ReadByte();  
        if(i != jbreak
      while(i != -&& j != -1);  
    catch(IOException exc) {  
      Console.WriteLine(exc.Message);  
    }  
    if(i != j)  
      Console.WriteLine("Files differ.")
    else 
      Console.WriteLine("Files are the same.")
  
    f1.Close();  
    f2.Close();  
  }  
}



           
       
Related examples in the same category
1. Create a file stream with new FileStream("test.bin", FileMode.Create)
2. Set File IO Permission to c:
3. FileStream with FileMode.Create and FileMode.Open
4. Reads lines separated by vertical barsReads lines separated by vertical bars
5. Reads strings from a file created in a text editorReads strings from a file created in a text editor
6. Create StreamReader from File Stream
7. illustrates reading and writing binary dataillustrates reading and writing binary data
8. illustrates use of FileStreamsillustrates use of FileStreams
9. illustrates use of FileStreams 2illustrates use of FileStreams 2
10. A simple disk-to-screen utility that demonstrates a FileReaderA simple disk-to-screen utility that 
   demonstrates a FileReader
11. Using FileStreams
12. An enhanced cipher component that maintains a log fileAn enhanced cipher component that maintains a log file
13. Reading and Writing Files
14. Seek from Begin
15. Write byte array to a file
www_.___j__a___v_a___2___s__._c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.