简单的C# dat文件读取方法

这篇博客展示了如何使用C#读取dat文件。通过`File.ReadAllLines`方法读取整个文件,然后遍历每一行。此外,还提供了一个ASP.NET下载文件的方法,将文件内容保存为新的文件。另外,还给出了将dat文件内容读取到文本框的代码示例。
摘要由CSDN通过智能技术生成

string filepath = @"C:/test.dat";
        string[] data = File.ReadAllLines(filepath, Encoding.Default);
        foreach (string line in data)
        {
            string a = line;
        }

 

来自朋友的一个测试小例子

 

以下为其他网页转载:ASP.NET做的web,服务端把一个文件转换成了Byte[]类型的字节数组返回,在客户端接这个数据啊,然后把这个文件保存下来

 

  /// <summary>
    /// 读取路径下的文件并保存为新文件
    /// </summary>
    /// <param name="filePath"></param>
    public static void DownLoadFile(string filePath)
    {
        HttpResponse rsp = HttpContext.Current.Response;

        if (filePath.StartsWith("~/"))
        {
            filePath = HttpContext.Current.Server.MapPath(filePath);
        }

        FileStream f = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

        rsp.ClearHeaders();
        rsp.ContentType = "application/x-msdownload";
        rsp.AddHeader("Content-Disposition", "attachment;filename= " + Path.GetFileName(filePath));
        rsp.AddHeader("Content-Length", f.Length.ToString());

        byte[] buffer = new byte[65536]; //ζ棬
       // byte[] mFileByte = new Byte[fileSize];

        while (true)
        {
            int b = f.Read(buffer, 0, buffer.Length);


            if (b == 0) break;
            rsp.BinaryWrite(buffer);
         
        }
        f.Close();
        rsp.Flush();
        rsp.Close();
    }


/******************************************************************/

 

 

dat文件数据读到文本框<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值