It says that its being used already, but it's being used by a stream reader, and a stream writer. I dont know what it wants me to do, I tried creating the file to no avail still gave me an error.
using System;
using System.IO;
namespace EncoderDecoder
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(compressor());
decoder(compressor());
Console.WriteLine(compare());
}
static string compressor()
{
string[] lines = System.IO.File.ReadAllLines(@"panda-small.txt");
string set = "0";
int count = 0;
string encoded = "";
foreach(string Line in lines)
{
for (int i = 0; i < Line.Length; i++)
{
if (Line.Substring(i, 1) == set)
{
count++;
}
else
{
encoded += count;
encoded += ",";
count = 0;
if (set == "0")
{
set = "1";
count++;
}
else
{
set = "0";
count++;
}
}
}
}
encoded += count;
return encoded;
}
static void decoder(string encoded)
{
File.Create("encoder.txt");
StreamWriter writer = new StreamWriter("encoded.txt");
string line = "";
string[] decoderArr = encoded.Split(",");
string set = "0";
int count = 0;
for(int i = 0; i < decoderArr.Length; i++)
{
if(decoderArr[i] == "ln" || decoderArr[i] == "")
{
Console.Write(Environment.NewLine);
}
else
{
for (int j = 0; j < Convert.ToInt32(decoderArr[i]); j++)
{
if(count == 35)
{
Console.WriteLine();
count = 0;
writer.WriteLine(line);
line = "";
}
count++;
line += set;
Console.Write(set);
}
if (set == "0")
{
set = "1";
}
else
{
set = "0";
}
}
}
}
static string compare()
{
StreamReader sr = new StreamReader("panda-small.txt");
StreamReader sr1 = new StreamReader("encoded.txt");
if (sr == sr1)
{
return "true";
}
return "false";
}
}
}