日期:2014-05-18 浏览次数:21038 次
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);
}
}
}
------解决方案--------------------
读安全,写不安全
------解决方案--------------------
这样就只能用lock了
------解决方案--------------------
读应该没问题,写可能会出错。
------解决方案--------------------
关于文件流 在任何时候基本都只能被一个 进程使用
读也要分情况
例如 你打开 一个文件 不做任何操作
再用程序操作这个文件 有可能也会报错