C#-文件读写

using System;
using System.IO;
using System.Text;
namespace 文件读写
{
class Program
{
static void Main(string[] args)
{
//bool Slave_IO_Running = false;
//bool Slave_SQL_Running = false;
//string file = @“F:\举个栗子\举个栗子\文件读写\目标文档.txt”;

        //using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
        //using (StreamReader sr = new StreamReader(fs))
        //{
        //try
        //{
        //    string currentLine = sr.ReadLine();//从当前流中读取一行字符并将数据作为字符串返回。


        //    while (currentLine != null)
        //    {
        //        //判断Slave_IO_Running是否在运行
        //        if (currentLine.Contains("Slave_IO_Running"))//值指示指定的 String 对象是否出现在此字符串中。
        //        {
        //            Slave_IO_Running = currentLine.Split(':')[1].Trim() == "Yes" ? true : false;
        //        }
        //        //判断Slave_SQL_Running是否在运行
        //        if (currentLine.Contains("Slave_SQL_Running"))
        //        {
        //            Slave_SQL_Running = currentLine.Split(':')[1].Trim() == "Yes" ? true : false;
        //        }
        //        currentLine = sr.ReadLine();
        //        Console.WriteLine(currentLine);
        //    }
        //    fs.Close();
        //    sr.Close();
        //}
        //catch
        //{
        //}
        /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
        string[] strs = new string[]

{
“10.100.182.89”,“10.100.182.90”
};
byte[] byData = new byte[100];
char[] charData = new char[1000];
using (StreamWriter writer = new StreamWriter(@“F:\写入目标文件.txt”))
{
foreach (string s in strs)
{
writer.WriteLine(s);
}
writer.Close();
}
/实例读写文件类/
//FileStream file1 = new FileStream(@“F:\举个栗子\举个栗子\文件读写\写入目标文件.txt”,FileMode.Open);
//file1.Seek(0,SeekOrigin.Begin);//指定开头
//file1.Read(byData, 0, 100);
//Decoder decoder = Encoding.Default.GetDecoder();
//decoder.GetChars(byData, 0, byData.Length, charData, 0);
//Console.WriteLine(charData);
//file1.Close();
/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7/

        StreamReader stream = new StreamReader(@"F:\\写入目标文件.txt", Encoding.Default);
        String line;
        while ((line = stream.ReadLine()) != null)
        {
            Console.WriteLine(line.ToString());
        }
        /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/

        FileStream file = new FileStream(@"F:\\at.txt", FileMode.Create);//在f 盘建一个 名为 at 的文本

        byte[] data = Encoding.Default.GetBytes("Hello World!");//内容
        //开始写入
        file.Write(data, 0, data.Length);
        //清空缓冲区、关闭流
        file.Flush();
        file.Close();


    }
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值