创建文件并写入内容
StreamWriter sw = new StreamWriter(url, “false 覆盖,true 追加”, Encoding.UTF8); sw.Write(“内容”); sw.Close();
读取文件内容
FileInfo info = new FileInfo("路径"); FileStream fs = new FileStream(pash, FileMode.OpenOrCreate, FileAccess.Read); byte[] b = new byte[info.Length]; fs.Read(b, 0,b.Length); UTF8Encoding utf = new UTF8Encoding(); string st = utf.GetString(b); fs.Close(); //st 文本内容
FileStream 个方法中也有创建、写入、读取等方法。
IO文本操作
时间: 2024-10-23 12:20:22