清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
读取文本文件代码片段
using System; using System.IO; public class TestReadFile { public static void Main(String[] args) { // Read text file C:\temp\test.txt FileStream fs = new FileStream(@c:\temp\test.txt , FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); String line=sr.ReadLine(); while (line!=null) { Console.WriteLine(line); line=sr.ReadLine(); } sr.Close(); fs.Close(); } }写文本文件代码片段
using System; using System.IO; public class TestWriteFile { public static void Main(String[] args) { // Create a text file C:\temp\test.txt FileStream fs = new FileStream(@c:\temp\test.txt , FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); // Write to the file using StreamWriter class sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine( First Line ); sw.WriteLine( Second Line); sw.Flush(); } }