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 SoniRank #694 · 3.5K reputationPosted Jan 9, 2010, 11:58 PM EST
Justin N18 reputationPosted Jan 10, 2010, 12:11 AM EST
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
Justin N18 reputationPosted Jan 10, 2010, 12:26 AM EST
Hiren SoniRank #694 · 3.5K reputationPosted Jan 10, 2010, 2:22 AM EST