c#读写建立临时文件
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();
}
补充:软件开发 , C# ,