Operating file system

xiaoxiao2021-03-06  108

Author: http: //blog.9cbs.net/china2001ok/ and write text files to create a new .aspx (mainly StreamWriter and StreamReader) using System.IO; // not less private void Button1_Click (object sender, System.EventArgs e) {streamWriter SW; // Call the CreateText method of the File class Returns a streamwriter after creating streamWriter, you can call its Write method to write text to the file SW = file.createtext (MAPPATH ("Ok.txt")); SW.writeLine (TextBox1.text); sw.close ();} private void button2_click (object sender, system.eventargs e) {// read text streamreader sr; // Decision path if the file exists

IF (file.exists ("ok.txt")))) {sr = file.opentext (mappath ("ok.txt")); TextBox1.text = sr.readline ();} else textbox1.text = " The file does not exist! ";} The construction of the binary file, write, read

Private void button3_click (object sender, system.eventargs e) {// write binary binaryWriter BW; // Create a binary filestream fs = new filestream (mappath ("mydata.data"), filemode.create; bw = new BinaryWriter (fs); // Initialize a binarywriter for (INT i = 0; i <200; i ) bw.write (i); // Write BW.CLOSE (); // Close}

Private void button4_click (object sender, system.eventargs e) {// Read binary binaryreader br; string str = ""; filestream fs = new filestream (Mappath ("MyData.Data"), filemode.open; br = new BinaryReader (fs); for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-100721.html

New Post(0)