c#中对文件的操作小结
来源:互联网 发布:sql 外键关联查询 编辑:程序博客网 时间:2024/06/05 04:55
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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");
}
}
中对文件的操作小结';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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");
}
}
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- c#中对文件的操作小结
- c#中对文件的操作小结
- c#中对文件的操作小结
- C#中对文件的操作小结
- c#中对文件的操作小结
- C# 对文件的操作小结
- C#对文件操作小结
- C#中对文件的操作
- C#中对RESX文件的操作
- C#中对文件的操作
- C#中对文件的操作
- C语言中对文件操作的小结
- C#对XML的操作小结
- C#对文件的操作
- C#对文件的操作
- C#对文件的操作
- c# 对文件的操作
- C#对文件的操作
- PHP+DBM的同学录程序(4)
- 老外编的程序(五)--如何使用全球标识符(GUID)
- PHP+DBM的同学录程序(2)
- Office XP Charting Examples in asp.net
- PHP+DBM的同学录程序(1)
- c#中对文件的操作小结
- 基于mysql的bbs设计(三)
- 自定义控件的使用二----DBGlobal.cs部分
- 基于mysql的bbs设计(四)
- 如何把存储在数据库中的图片根据自己的需要的大小显示出来。【转】
- 基于mysql的bbs设计(二)
- 自定义控件的使用例子一
- 支持oicq头像的留言簿(二)
- c# 中如何定义和接收消息?(转)