我使用的方法是:
string filePath = ConfigStrList.LogPath + string.Format("Log-{0}.log",DateTime.Now.ToString("yyyy-MM") );
if ( File.Exists(filePath) )
{
StreamReader sr = null;
try
{
sr = File.OpenText(filePath); StrLogContent = sr.ReadToEnd();
}
finally
{
if (sr != null)
{
sr.Close();
} }
}因为这个日志文件是被一直占用的。每次读取都报错:
The process cannot access the file "G:\Back_Log\Log-2007-12.log" because it is being used by another process. 不知道这种文件该如何读取啊。、?
string filePath = ConfigStrList.LogPath + string.Format("Log-{0}.log",DateTime.Now.ToString("yyyy-MM") );
if ( File.Exists(filePath) )
{
StreamReader sr = null;
try
{
sr = File.OpenText(filePath); StrLogContent = sr.ReadToEnd();
}
finally
{
if (sr != null)
{
sr.Close();
} }
}因为这个日志文件是被一直占用的。每次读取都报错:
The process cannot access the file "G:\Back_Log\Log-2007-12.log" because it is being used by another process. 不知道这种文件该如何读取啊。、?
解决方案 »
- 一个收索功能,新人求助。
- C#报表 请问有没有一种报表可以让用户自给绘制报表,就好像用户在调用编辑报表的页面
- vs初学winform的疑惑
- vb函数转换c#的问题,在线等!
- 路由器上web系统是什么后台技术的?
- 3个Timer的区别(System.Threading.Timer,System.Windows.Forms.Timer,System.Timers.Timer)
- 求救,遇到“在此上下文中不允许使用名称 "**"。.....不允许使用列名。”
- 如何让查询输出单行数据
- 在C#中使用web browser控件,如何得到该控件网页的html源码???
- vs真要256以上内存吗?
- combobox的一个简单问题
- ftpwebrequest登录FTP服务器后怎么切换目录?
还请高手出来~~~~
楼主hansonbo(中国快富强)2002-07-16 11:01:13 在 .NET技术 / C# 提问
如何读取正在使用中的文件!
file1.txt 的正在被其他的文件使用。
pStrm = new StreamReader(file1.txt, System.Text.Encoding.Default );
while( (sLine = this.pStrm.ReadLine() ) != null )
{
...
问题点数:0、回复次数:11
Top
1 楼hansonbo(中国快富强)回复于 2002-07-16 11:52:24 得分 0 急!急!
Top2 楼snewxf(心疤)回复于 2002-07-16 12:30:09 得分 0 关注!!!!!
Top3 楼hansonbo(中国快富强)回复于 2002-07-16 13:22:25 得分 0 真的很难吗?
竟然没人能回答?????????
Top4 楼bigtree21cn(大树)回复于 2002-07-16 16:37:51 得分 0 如果被訪問的文件是獨佔式訪問,我覺得沒辦法胃。
Top5 楼juqiang(方枪枪(正在修炼伤心小箭))回复于 2002-07-16 17:50:02 得分 0 和你的代码没有关系,主要是这个文件以什么mode被打开的。
Top6 楼corex(凡人核心)回复于 2002-07-17 00:03:53 得分 0 正如bigtree21cn所说,如果文件是被其它进程以独占方式打开的话,
你是连读都无法读的,更不用说写。
Top7 楼hansonbo(中国快富强)回复于 2002-07-17 09:14:12 得分 0 可是,我用notepad能打开,我想用Application就能读。
我仅仅是想读这个Txt文件。
Top8 楼hlf(一个笨蛋)回复于 2002-07-17 10:28:29 得分 0 关注
Top9 楼hansonbo(中国快富强)回复于 2002-08-12 15:22:29 得分 0 本以为这个问题很容易,却没想到如此的难!
还没人能解决!
我想在请教一次。
一个正使用中的文件,用notepad可以读,但我想用程序读,
但是不行!错误显示,文件正在使用中!
Top10 楼snewxf(心疤)回复于 2002-08-18 23:45:07 得分 0 第二次UP!!!!!!
StreamReader reader = new StreamReader(fs);