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文件数据读到文本框<