asp.net c#把数据写入到txt文件中代码
bool checkfile = file.exists(filename);
filestream fs = new filestream(filename, filemode.openorcreate, fileaccess.write);
streamwriter sw = new streamwriter(fs, system.text.encoding.getencoding("gb2312"));//通过指定字符编码方式可以实现对汉字的支持,否则在用记事本打开查看会出现乱码
sw.flush();
if (checkfile)
{
sw.basestream.seek(0, seekorigin.end);//移动到结尾
}
else
{
sw.basestream.seek(0, seekorigin.begin);
}
string temp = "随便写点东西www.111com.net";
sw.writeline(temp);
sw.flush();
sw.close();filestream fs = new filestream(path, filemode.create);
streamwriter sw = new streamwriter(fs);
sw.writeline(textbox1.text);
sw.close();
fs.close();