how do i stop this from throwing an IOException?
namespace BrowseFileSystem
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(input);
ms.WriteTo(File.Create(@"f:\textfile2.txt"));
sw.Close();
ms.Close();
//while (true)
//{
// try
// {
StreamReader sr = new StreamReader(@"f:\textfile2.txt");
Console.WriteLine(sr.ReadToEnd());
// }
// catch (Exception) { }
//}
}
}
}
Loading
Hiren SoniPosted Jan 10, 2010, 7:22 AM
Justin NPosted Jan 10, 2010, 5:26 AM
Justin NPosted Jan 10, 2010, 5:11 AM
namespace BrowseFileSystem
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(input);
ms.WriteTo(File.Create(@"f:\textfile2.txt"));
sw.Close();
ms.Dispose();
if (File.Exists(@"f:\textfile2.txt"))
{
StreamReader sr = new StreamReader(@"f:\textfile2.txt");
Console.WriteLine(sr.ReadToEnd());
}
}
}
}
It says that textfile2 is being used by another process
Hiren SoniPosted Jan 10, 2010, 4:58 AM