C
Chris
hi, i'm having trouble with file access/permssions.
is it possible for me to have one app writing to a file and another app
reading from the same file?
i'm writing a log reader that hopefully will read a log file and output
whatever is appended to the log in real time.
to demonstrate my problem, i wrote a couple apps.
run app1 first and it will block after the file is opened, so you can start
app2 and see the problem i'm having.
make sure they're both in the same directory.
thanks,
chris
// app1.cs:
using System;
using System.IO;
class App1
{
static void Main()
{
FileStream fs = new FileStream("trace.log", FileMode.Append,
FileAccess.Write, FileShare.Read);
Console.WriteLine("now start app2");
Console.Read(); // block so app2 can be run
fs.Close();
}
}
// app2.cs:
using System;
using System.IO;
class App2
{
static void Main()
{
try {
FileStream fs = new FileStream("trace.log", FileMode.Open,
FileAccess.Read);
Console.WriteLine("successful");
} catch(Exception ex) {
Console.WriteLine(ex.ToString());
}
Console.WriteLine("any key to close");
Console.Read(); // block
}
}
is it possible for me to have one app writing to a file and another app
reading from the same file?
i'm writing a log reader that hopefully will read a log file and output
whatever is appended to the log in real time.
to demonstrate my problem, i wrote a couple apps.
run app1 first and it will block after the file is opened, so you can start
app2 and see the problem i'm having.
make sure they're both in the same directory.
thanks,
chris
// app1.cs:
using System;
using System.IO;
class App1
{
static void Main()
{
FileStream fs = new FileStream("trace.log", FileMode.Append,
FileAccess.Write, FileShare.Read);
Console.WriteLine("now start app2");
Console.Read(); // block so app2 can be run
fs.Close();
}
}
// app2.cs:
using System;
using System.IO;
class App2
{
static void Main()
{
try {
FileStream fs = new FileStream("trace.log", FileMode.Open,
FileAccess.Read);
Console.WriteLine("successful");
} catch(Exception ex) {
Console.WriteLine(ex.ToString());
}
Console.WriteLine("any key to close");
Console.Read(); // block
}
}