#freeze
[[.NET]]
よくある定番。
ただしエラー処理が甘いから、そこはちゃんとしないとね。
あと、書き込みで追記したい時は、第二パラメータを true にしてね。
/// <summary>
/// loadfile
/// </summary>
/// <param name="fn"></param>
/// <returns></returns>
private static string loadfile(string fn)
{
string text = "";
try
{
StreamReader sr = new StreamReader(fn, Encoding.GetEncoding("Shift_JIS"));
text = sr.ReadToEnd();
sr.Close();
}
catch (Exception e) // 例外
{
text = e.Message;
}
return (text);
}
/// <summary>
/// savefile
/// </summary>
/// <param name="fn"></param>
/// <param name="x"></param>
/// <returns></returns>
private static string savefile(string fn, string x)
{
string r = "";
try
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(fn, false, System.Text.Encoding.GetEncoding("shift_jis"));
sw.Write(x);
sw.Close();
}
catch (Exception ex)
{
r = ex.Message;
}
return (r);
}