Create a Temporary File - CSharp File IO

CSharp examples for File IO:File

Description

Create a Temporary File

Demo Code


using System;/*from www.  ja  v  a2s .  co m*/
using System.IO;

    static class MainClass
    {
        static void Main()
        {
            string tempFile = Path.GetTempFileName();

            Console.WriteLine("Using " + tempFile);

            using (FileStream fs = new FileStream(tempFile, FileMode.Open))
            {
                // (Write some data.)
            }

            // Now delete the file.
            File.Delete(tempFile);

        }
    }

Result


Related Tutorials