class Temp
{
/// <summary>
/// 寫臨時文件
/// </summary>
/// <param name="user">要寫入文件的內容 不帶後綴</param>
/// <param name="password">要寫入的內容</param>
public void WriteTemp(string user,string password)
{
string mypath; //保存路徑
//得到當程序的路徑
int i = Application.ExecutablePath.LastIndexOf (@"");
//得到要保存文件的位置
mypath = Application.ExecutablePath.Substring(0,i);
FileInfo myfile = new FileInfo(mypath +@""+ user + ".tmp");
//判斷文件是否存在
if (!myfile.Exists)
{
//文件不存在建立一個文件
myfile.Create();
}
FileStream mystream = new FileStream(myfile.ToString() ,FileMode.Open);
StreamWriter mywriter = new StreamWriter(mystream,Encoding.Unicode );
//寫入數據
mywriter.WriteLine(password);
mywriter.Flush();
mywriter.Close();
}