如何以共享方式打开.txt文件

wubaowang 2008-02-15 12:33:38


using (StreamReader srd = new StreamReader(fileName, System.Text.Encoding.Default))
{
while ((objet = srd.ReadLine()) != null)
{
txtRead += objet + "\r\n";
rows++;
}
srd.Close();
}


如何以共享方式打开.txt文件
...全文
274 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovehongyun 2008-02-20
  • 打赏
  • 举报
回复
Read好像就是共享的.
lake_cx 2008-02-20
  • 打赏
  • 举报
回复
public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
{
if ((path == null) || (encoding == null))
{
throw new ArgumentNullException((path == null) ? "path" : "encoding");
}
if (path.Length == 0)
{
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
}
if (bufferSize <= 0)
{
throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
}
Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, FileOptions.SequentialScan);
this.Init(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize);
}

yhy0611 2008-02-20
  • 打赏
  • 举报
回复
接分喽
genlinux 2008-02-20
  • 打赏
  • 举报
回复
FileStream fs = File.Open(file, FileMode.Open,FileAccess.Read,FileShare.Read);
默认下打开的文件是被打开者拥有的, 而且是不分享的。
using (StreamReader srd = new StreamReader(fs))
{
while ((objet = srd.ReadLine()) != null)
{
txtRead += objet + "\r\n";
rows++;
}
srd.Close();
}
vrhero 2008-02-15
  • 打赏
  • 举报
回复
谁告诉你StreamReader打开文件不是共享方式的?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧