A file copy program. | Lecture 9 - slide 11 : 30 Program 1 |
using System; using System.IO; public class CopyApp { public static void Main(string[] args) { FileInfo inFile = new FileInfo(args[0]), outFile = new FileInfo(args[1]); FileStream inStr = inFile.OpenRead(), outStr = outFile.OpenWrite(); int c; do{ c = inStr.ReadByte(); if(c != -1) outStr.WriteByte((byte)c); } while (c != -1); inStr.Close(); outStr.Close(); } } | Binary FileStream objects for input and output. In a loop, read a byte from inStr and write the byte to outStr. Close both streams. |