G
greg_dorian
Guest
Hello,
Trying to understand a project that I have to refactor, I found these methods in a kind of repository classes
public static void CreateAllText(string path, string contenidos, Encoding encoding)
{
if (!File.Exists(path))
{
using (FileStream FileText = new FileStream(path, FileMode.Create, FileAccess.Write))
{
using (StreamWriter sDocwriter = new StreamWriter(FileText, encoding, 1024, false))
{
sDocwriter.Write(contenidos);
}
}
}
else
{
throw new ArgumentNullException("Error: file Exists overwrite");
}
}
public static void AppendText(string path, string contenidos, Encoding encoding)
{
if (File.Exists(path))
{
using (FileStream FileText = new FileStream(path, FileMode.Append, FileAccess.ReadWrite))
{
using (StreamWriter sDocwriter = new StreamWriter(FileText, encoding, 1024, false))
{
sDocwriter.Write(contenidos);
}
}
}
else
{
throw new ArgumentNullException("Error: Not File exists");
}
}
first one write all document, but creates a FileStream and then a StreamWriter
the other is to append FileStream but Writing in a StreamWriter??? I need a explanation!!
Continue reading...
Trying to understand a project that I have to refactor, I found these methods in a kind of repository classes
public static void CreateAllText(string path, string contenidos, Encoding encoding)
{
if (!File.Exists(path))
{
using (FileStream FileText = new FileStream(path, FileMode.Create, FileAccess.Write))
{
using (StreamWriter sDocwriter = new StreamWriter(FileText, encoding, 1024, false))
{
sDocwriter.Write(contenidos);
}
}
}
else
{
throw new ArgumentNullException("Error: file Exists overwrite");
}
}
public static void AppendText(string path, string contenidos, Encoding encoding)
{
if (File.Exists(path))
{
using (FileStream FileText = new FileStream(path, FileMode.Append, FileAccess.ReadWrite))
{
using (StreamWriter sDocwriter = new StreamWriter(FileText, encoding, 1024, false))
{
sDocwriter.Write(contenidos);
}
}
}
else
{
throw new ArgumentNullException("Error: Not File exists");
}
}
first one write all document, but creates a FileStream and then a StreamWriter
the other is to append FileStream but Writing in a StreamWriter??? I need a explanation!!
Continue reading...