标题:[转帖]C#文件操作
取消只看楼主
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
结帖率:66.67%
 问题点数:0 回复次数:0 
[转帖]C#文件操作

1、建立一个文本文件 public class FileClass { public static void Main() { WriteToFile(); } static void WriteToFile() { StreamWriter SW; SW=File.CreateText("c:\MyTextFile.txt"); SW.WriteLine("God is greatest of them all"); SW.WriteLine("This is second line"); SW.Close(); Console.WriteLine("File Created SucacessFully"); } }

2、读文件 public class FileClass { public static void Main() { ReadFromFile("c:\MyTextFile.txt"); } static void ReadFromFile(string filename) { StreamReader SR; string S; SR=File.OpenText(filename); S=SR.ReadLine(); while(S!=null) { Console.WriteLine(S); S=SR.ReadLine(); } SR.Close(); } }

3、追加操作 public class FileClass { public static void Main() { AppendToFile(); } static void AppendToFile() { StreamWriter SW; SW=File.AppendText("C:\MyTextFile.txt"); SW.WriteLine("This Line Is Appended"); SW.Close(); Console.WriteLine("Text Appended Successfully"); } }

搜索更多相关主题的帖子: 转帖 public 文件 void 
2005-05-15 00:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-18223-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042365 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved