CHAPTER 16 (Photoshop web design) THE SYSTEM.IO NAMESPACE 529 static
Wednesday, February 20th, 2008CHAPTER 16 THE SYSTEM.IO NAMESPACE 529 static void Main(string[] args) { … FileInfo f6 = new FileInfo(@”C:Test5.txt”); StreamWriter swriter = f6.CreateText(); // Use the StreamWriter object… swriter.Close(); FileInfo f7 = new FileInfo(@”C:FinalTest.txt”); StreamWriter swriterAppend = f7.AppendText(); // Use the StreamWriter object… swriterAppend.Close(); } As you would guess, the StreamWriter type provides a way to write character data to the underlying file. Working with the File Type The File type provides functionality almost identical to that of the FileInfo type, using a number of static members. Like FileInfo, File supplies AppendText(), Create(), CreateText(), Open(), OpenRead(), OpenWrite(), and OpenText() methods. In fact, in many cases, the File and FileStream types may be used interchangeably. To illustrate, each of the previous FileStream examples can be simplified by using the File type instead: static void Main(string[] args) { // Obtain FileStream object via File.Create(). FileStream fs = File.Create(@”C:Test.dat”); fs.Close(); // Obtain FileStream object via File.Open(). FileStream fs2 = File.Open(@”C:Test2.dat”, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); fs2.Close(); // Get a FileStream object with read-only permissions. FileStream readOnlyStream = File.OpenRead(@”Test3.dat”); readOnlyStream.Close(); // Get a FileStream object with write-only permissions. FileStream writeOnlyStream = File.OpenWrite(@”Test4.dat”); writeOnlyStream.Close(); // Get a StreamReader object. StreamReader sreader = File.OpenText(@”C:boot.ini”); sreader.Close();
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.