|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace RayTracer
{
public class Helpers
{
public static bool LoadTextFile(string sFilename, ref string sTextFromFile)
{
sTextFromFile = "";
try
{
StreamReader oStreamReader = new StreamReader(sFilename);
sTextFromFile = oStreamReader.ReadToEnd();
oStreamReader.Close();
oStreamReader.Dispose();
}
catch(Exception ex)
{
sTextFromFile = ex.ToString();
return false;
}
return true;
}
public static bool SaveTextFile(string sFilename, string sText)
{
try
{
StreamWriter oStreamWriter = new StreamWriter(sFilename);
oStreamWriter.Write(sText);
oStreamWriter.Flush();
oStreamWriter.Close();
oStreamWriter.Dispose();
}
catch
{
return false;
}
return true;
}
public static string SaveTempFile(string sText)
{
string FileName = Path.GetTempFileName();
FileStream File_Stream = new FileStream(FileName, FileMode.Append, FileAccess.Write);
StreamWriter FileWriter = new StreamWriter(File_Stream);
try
{
FileWriter.BaseStream.Seek(0, SeekOrigin.End);
FileWriter.Write(sText);
}
catch (IOException)// ex)
{
//Debug.Assert(false, ex.ToString());
}
finally
{
FileWriter.Close();
}
return FileName;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.