- Code: Select all
string line = null;
string line_to_delete = message;
using (StreamReader reader = new StreamReader(Environment.CurrentDirectory + "/text/cmdautoload.txt"))
{
using (StreamWriter writer = new StreamWriter(Environment.CurrentDirectory + "/text/cmdautoload.txt"))
{
while ((line = reader.ReadLine()) != null)
{
if (String.Compare(line, line_to_delete) == 0)
continue;
writer.WriteLine(line);
}
}
}
Error:
- Code: Select all
-------------------------
----19/02/2014 14:15:55 ----
Type: IOException
Source: mscorlib
Message: The process cannot access the file 'C:\Users\Leebyrne115\Desktop\Zombie Server - Copy\text\cmdautoload.txt' because it is being used by another process.
Target: WinIOError
Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path)
at MCDzienny.CmdCmdRemove.Use(Player p, String message)
at MCDzienny.Player.<>c__DisplayClass28.<HandleCommand>b__23()
-------------------------
I don't understand how the file could already been in use, I had it closed, and doesn't it only be used at server start-up? any solutions?