C #: Files of the DrawWriting and File Directory

xiaoxiao2021-03-06  60

Author: David Eulerdate: 2004/11 / 16Email: DE_EULER-David@yahoo.com There is any problem, please contact me :) Press the read and write file to determine if the file exists: file.exists (string filepath) Directory Present: Directory.exists ("D: // LastestVersion")

Read the file by line: int filecount = 0; // Open the file Just specified Such this no one else can use it it. Streamreader sr = new streamreader (TextBox1.Text.trim ()); while (sr.peek ()> -1) // streamreader.peek () Returns the next available character, but does not use it {listbox1.items.add (sr.readline ()); FileCount ;} sr.close ();

Write file by line: streamwriter sw = new streamwriter ("d: //Result.txt"); for (int i = 0; i <10; i ) {sw.writeline ("this is the first i.tostring () "Row data");

File directory dialog box that is used file using filtering condition: string resultFile = ""; OpenFileDialog openFileDialog1 = new OpenFileDialog (); openFileDialog1.InitialDirectory = "D: // Patch"; openFileDialog1.Filter = "All files (* .. *) | * * | txt files (* .txt) | * .txt "; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog () == DialogResult.OK) resultFile = openFileDialog1. Filename;

Use the directory dialog box: string resultFolder = ""; FolderBrowserDialog openFolderDialog1 = new FolderBrowserDialog (); openFolderDialog1.RootFolder = Environment.SpecialFolder.MyComputer; if (openFolderDialog1.ShowDialog () == DialogResult.OK) resultFolder = openFolderDialog1.SelectedPath; traversal Directory, save the file list: // Travers the directory D: /Patch/erpv3.0-1/dll, place all file lists into d: /listfiles.txt: String [] files = Directory.getFiles (@ "D : /Patch/erpv3.0-1/dll ");

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

New Post(0)