服务端StreamReader的方式读取txt数据求指教

Json1204 2012-05-10 03:41:10
我把txt文件当数据源 放服务端
如果以StreamReader的方式读取txt数据,当多个用户同时访问时候 这个会出错吗?
...全文
100 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ycproc 2012-05-10
  • 打赏
  • 举报
回复
关于文件流 在任何时候基本都只能被一个 进程使用

读也要分情况

例如 你打开 一个文件 不做任何操作

再用程序操作这个文件 有可能也会报错
dalmeeme 2012-05-10
  • 打赏
  • 举报
回复
读应该没问题,写可能会出错。
Json1204 2012-05-10
  • 打赏
  • 举报
回复
先试用 试试 估计不会出问题 因为不修改数据
tiangong789 2012-05-10
  • 打赏
  • 举报
回复
这样就只能用lock了
Json1204 2012-05-10
  • 打赏
  • 举报
回复
就怕出现上面这种问题
Json1204 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
读安全,写不安全
[/Quote]
会不会报错:正由另一进程使用,因此该进程无法访问此文件
bdmh 2012-05-10
  • 打赏
  • 举报
回复
读安全,写不安全
Json1204 2012-05-10
  • 打赏
  • 举报
回复
写我知道怎么写 不知道会不会出问题 请教 论坛上面的大牛来给点意见
wy811007 2012-05-10
  • 打赏
  • 举报
回复
应该木事吧.

参照msdn

using System;
using System.IO;

class Test
{
public static void Main()
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}

111,126

社区成员

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

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

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