标题:c# 如何读取TXT 文件内容
只看楼主
kill1224808
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-17
 问题点数:0 回复次数:2 
c# 如何读取TXT 文件内容
c# 如何读取TXT 文件内容?

请各位高手指点一下
搜索更多相关主题的帖子: 文件内容 TXT 
2007-05-17 17:41
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
StreamRead

飘过~~
2007-05-17 18:03
epng2005
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-5-19
得分:0 
有两中读法 一种是以读字符串的方式读出来的,比如:
public string ReadFile(string filepath) //文本文件的读操作
{
string content = File.ReadAllText(filepath);
return content;
}
这只针对文本文件,就是txt文件
我们一般的文件都得以二进制流的方式读出来,比如:
public string ReadFileStream(string filepath) //二进制流文件的读操作
{
FileStream fs = new FileStream(filepath,FileMode.Open,FileAccess.Read);
long i = fs.Length;
byte[] b = new byte[i];
fs.Read(b,0,b.Length);
UTF8Encoding temp = new UTF8Encoding(true);
string data = temp.GetString(b);
return data;
}
希望对你有帮助...

怡人的天气转去,温柔的香气飘来(怡香工作室www..cn)
2007-05-19 16:46



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




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

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