string SglNo = "2TXTAAAA";
string UserName = "小熊";
string sex = "1";
string strbirthdate = "1997-09-08";
string Height = "170";
string dirpath = "B:\\TXT";
string FilePath = dirpath + "\\" + SglNo + ".TXT";
string id = SglNo.PadLeft(10, '0');
//2009050001|小熊|1|1975-10-24|172.3
if (File.Exists(FilePath) == false)//表示有这个文档
{
//string[] contents = { id, "|", UserName, "|", sex, "|", strbirthdate, "|", Height };
//StreamWriter newwriter = File.CreateText(FilePath);
//newwriter.WriteLine(id + "|" + UserName + "|" + sex + "|" + strbirthdate + "|" + Height);//开始写入值
//newwriter.Close();//关闭文件
//ANSIWriteAllText
//File.WriteAllLines(FilePath, contents, Encoding.UTF8);
StreamWriter sw = new StreamWriter(FilePath, true, System.Text.Encoding.UTF8);
sw.WriteLine(id + "|" + UserName + "|" + sex + "|" + strbirthdate + "|" + Height);
sw.Close();
}
C#创建Encoding.UTF8的.txt文件
最新推荐文章于 2024-05-04 21:03:09 发布