Uses methods in the File class to dheck whether a file exists : File « File Stream « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » File Stream » FileScreenshots 
Uses methods in the File class to dheck whether a file exists

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

// Exists.cs -- Uses methods in the File class to dheck whether a file exists.
//              If it exists, it then opens and reads the file to the console.
//
//              Compile this program with the following command line
//                  C:>csc Exists.cs
using System;
using System.IO;

namespace nsStreams
{
    public class Exists
    {
        static public void Main (string [] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine ("Please enter a file name");
                return;
            }
            if (!File.Exists (args[0]))
            {
                Console.WriteLine (args[0" does not exist");
                return;
            }
            StreamReader reader;
            try
            {
                reader = File.OpenText (args[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine (e.Message);
                Console.WriteLine ("Cannot open " + args[0]);
                return;
            }
            while (reader.Peek() >= 0)
            {
                Console.WriteLine (reader.ReadLine ());
            }
            reader.Close ();
        }
    }
}


           
       
Related examples in the same category
1. illustrates the File classillustrates the File class
2. illustrates the FileAttributes enumerationillustrates the FileAttributes enumeration
3. illustrates the FileInfo classillustrates the FileInfo class
4. illustrates the FileSystemWatcher classillustrates the FileSystemWatcher class
5. File class to check whether a file exists, open and read
6. Uses methods in the File class to check the status of a file
www.___ja__va_2s_.__c_o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.