多进程,不是多线程就是我生成的应用程序,不能同时打开多个应用程序,只能等第一个读取文件完毕后,再打开第二个去读取文件,否则显示读取文件冲突不能像utralEdit那样,同时瞬发的对一个文件多次读。下面是我读文件的代码:
FileStream fs = new FileStream(fileName, FileMode.Open); byte[] version = new byte[32];
fs.Read(version, 0, version.Length);
String ver = Encoding.UTF8.GetString(version, 0, version.Length); String verNumStr = CRegex.GetMatch(ver, "KTDictSeg Dict V(.+)", true);
while (fs.Position < fs.Length)
{
byte[] buf = new byte[sizeof(int)];
fs.Read(buf, 0, buf.Length);
int length = BitConverter.ToInt32(buf, 0); buf = new byte[length]; T_DictStruct dict = new T_DictStruct(); fs.Read(buf, 0, buf.Length); dict.Word = Encoding.UTF8.GetString(buf, 0, length - sizeof(int) - sizeof(double));
dict.Pos = BitConverter.ToInt32(buf, length - sizeof(int) - sizeof(double));
dict.Frequency = BitConverter.ToDouble(buf, length - sizeof(double));
dictFile.Dicts.Add(dict);
}
=================================================================================
StreamReader sr = File.OpenText(strAmbiguousChsNamePath);
string strLine = null;
while ((strLine = sr.ReadLine()) != null)
{
strLine = strLine.Trim();
if (strLine == "")
continue;
if (!m_AmbiguousChsNameTbl.ContainsKey(strLine))
m_AmbiguousChsNameTbl.Add(strLine, "");
}
sr.Close();=======================================================================================C#默认读文件的打开文件的句柄后,在读取结束之前。是不是其他的读取就不能再对这个文件读取了?
我网上搜了一下,有个FileInfo类,是不是可以实现我的这个要求。
FileStream fs = new FileStream(fileName, FileMode.Open); byte[] version = new byte[32];
fs.Read(version, 0, version.Length);
String ver = Encoding.UTF8.GetString(version, 0, version.Length); String verNumStr = CRegex.GetMatch(ver, "KTDictSeg Dict V(.+)", true);
while (fs.Position < fs.Length)
{
byte[] buf = new byte[sizeof(int)];
fs.Read(buf, 0, buf.Length);
int length = BitConverter.ToInt32(buf, 0); buf = new byte[length]; T_DictStruct dict = new T_DictStruct(); fs.Read(buf, 0, buf.Length); dict.Word = Encoding.UTF8.GetString(buf, 0, length - sizeof(int) - sizeof(double));
dict.Pos = BitConverter.ToInt32(buf, length - sizeof(int) - sizeof(double));
dict.Frequency = BitConverter.ToDouble(buf, length - sizeof(double));
dictFile.Dicts.Add(dict);
}
=================================================================================
StreamReader sr = File.OpenText(strAmbiguousChsNamePath);
string strLine = null;
while ((strLine = sr.ReadLine()) != null)
{
strLine = strLine.Trim();
if (strLine == "")
continue;
if (!m_AmbiguousChsNameTbl.ContainsKey(strLine))
m_AmbiguousChsNameTbl.Add(strLine, "");
}
sr.Close();=======================================================================================C#默认读文件的打开文件的句柄后,在读取结束之前。是不是其他的读取就不能再对这个文件读取了?
我网上搜了一下,有个FileInfo类,是不是可以实现我的这个要求。
System.IO.StreamReader _SR = new StreamReader(_Fs);
加上 FileShare.Read 看看.