File IO speed problem

  • Thread starter Thread starter Cyrus
  • Start date Start date
C

Cyrus

I always find that when there is a write operation immediately after the
read operation, it throws this exception

An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
"D:\Projects\pro.dat" because it is being used by another process.

how to solve this problem
 
Cyrus said:
I always find that when there is a write operation immediately after the
read operation, it throws this exception

An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
"D:\Projects\pro.dat" because it is being used by another process.

how to solve this problem

Have you closed the reading stream before you start writing again?
 
* "Cyrus said:
I always find that when there is a write operation immediately after the
read operation, it throws this exception

An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
"D:\Projects\pro.dat" because it is being used by another process.

how to solve this problem

Post your code.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
StreamReader sr = new
StreamReader(File.OpenRead(Environment.CurrentDirectory + "\\Inipro.dat"));
// StreamReader sr = new StreamReader(keyFile.OpenRead());

if (sr.ReadLine() != null)
{
prodCode = this.Decode(sr.ReadLine());
actCode = this.Decode(sr.ReadLine());
pass = VerifyActCode();
}
sr.Close();

UnicodeEncoding byteConverter = new UnicodeEncoding();
// StreamWriter sw = new StreamWriter(keyFile.OpenWrite());
StreamWriter sw = new
StreamWriter(File.OpenWrite(Environment.CurrentDirectory + "\\Inipro.dat"));

sw.WriteLine(byteConverter.GetString(this.GetRandomBytes()));
sw.WriteLine(this.Encode(prodCode));
sw.WriteLine(this.Encode(actCode));
sw.Flush();
sw.Close();
 
sorry i solved...

Cyrus said:
StreamReader sr = new
StreamReader(File.OpenRead(Environment.CurrentDirectory + "\\Inipro.dat"));
// StreamReader sr = new StreamReader(keyFile.OpenRead());

if (sr.ReadLine() != null)
{
prodCode = this.Decode(sr.ReadLine());
actCode = this.Decode(sr.ReadLine());
pass = VerifyActCode();
}
sr.Close();

UnicodeEncoding byteConverter = new UnicodeEncoding();
// StreamWriter sw = new StreamWriter(keyFile.OpenWrite());
StreamWriter sw = new
StreamWriter(File.OpenWrite(Environment.CurrentDirectory + "\\Inipro.dat"));

sw.WriteLine(byteConverter.GetString(this.GetRandomBytes()));
sw.WriteLine(this.Encode(prodCode));
sw.WriteLine(this.Encode(actCode));
sw.Flush();
sw.Close();
 
....and the solution WAS?


--
Eric Newton
C#/ASP Application Developer
(e-mail address removed)-software.com [remove the first "CC."]

cyrus said:
just silly mistake :-P
 
Back
Top