一聚教程网:一个值得你收藏的教程网站

热门教程

asp.net C#把数据写入到txt文件中代码

时间:2022-06-25 05:08:00 编辑:袖梨 来源:一聚教程网

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();

热门栏目