-----------------写入内容----------------

string userfile = "UserData.txt";
StreamWriter sw = null;

//判断是否存在
if (!System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(@"../" + userfile)))
{

  //不存在,新建
  System.IO.File.Create(System.Web.HttpContext.Current.Server.MapPath(@"../" + userfile)).Close();
  sw = new StreamWriter(Server.MapPath(@"../" + userfile), true, System.Text.Encoding.Default);

  sw.Write("用户名");
  sw.Write("," + "手机号");
  sw.Write("," + "地址");
  sw.WriteLine();
}
else
{
  sw = new StreamWriter(Server.MapPath(@"../" + userfile), true, System.Text.Encoding.Default);
}

  sw.Write(“想要写入的内容”);
  sw.WriteLine();
  sw.Close(); //关闭流

-----------------读取内容----------------

string uListPath = @"../" + "UserData.txt";

string content = string.Empty;
if (!System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(uListPath)))
{
  //文件不存在
}
else
{
  using (StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Server.MapPath(uListPath),   System.Text.Encoding.Default))
  {
    content = sr.ReadToEnd(); // 读取txt文件内容
  }
}

mvc 读写txt文档的更多相关文章

  1. C# 将内容写入txt文档

    <1>  FileStream fs = new FileStream(@"D:\text.txt", FileMode.Append); StreamWriter s ...

  2. QTP操作txt文档

    QTP可以在txt文件(文本文件中读取数据) 首先创造一个文档对象 set fso = createObject("scripting.filesystemobject") 然后用 ...

  3. 利用IDL将一个txt文档拆分为多个

    测试.txt文档,每47行的格式相同,通过代码每47行存为一个txt,txt文档命名为其第一行数据. 代码如下: file='G:\data\测试.txt' openr,lun,file,/Get_L ...

  4. 用matlab查找txt文档中的关键字,并把关键字后面的数据存到起来用matlab处理

    用matlab查找txt文档中的关键字,并把关键字后面的数据存到起来用matlab处理 我测了一组数据存到txt文件中,是个WIFI信号强度文档,里面有我们需要得到的数据,有没用的数据,想用matla ...

  5. WebService 实现BS环境与BS环境传递参数,根据参数生成txt文档

    客户端: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Client.as ...

  6. C#操作Xml:通过XmlDocument读写Xml文档

    什么是Xml? Xml是扩展标记语言的简写,是一种开发的文本格式.关于它的更多情况可以通过w3组织了解http://www.w3.org/TR/1998/REC-xml-19980210.如果你不知道 ...

  7. 将txt文档按行分割

    昨天遇到了一个需求,需要将txt文档按行分割,并指定了行数, 最近在用python,就在网上搜了一下,在参考了http://blog.csdn.net/zhang_red/article/detail ...

  8. 用C++向一个txt文档中写数据

    bool CMaked::WriteFileMake(CString filePath, const char *isChange) { ofstream file; //filePath为该txt文 ...

  9. 一个简易的Python爬虫,将爬取到的数据写入txt文档中

    代码如下: import requests import re import os #url url = "http://wiki.akbfun48.com/index.php?title= ...

随机推荐

  1. java POI创建Excel示例(xslx和xsl区别 )

    Java用来处理office类库有很多,其中POI就是比较出名的一个,它是apache的类库,现在版本到了3.10,也就是2014年2月8号这个版本. 在处理PPT,Excel和Word前,需要导入以 ...

  2. php session阻塞页面分析及优化 (session_write_close session_commit使用)

    转: http://www.tuicool.com/articles/bqeeey 首先看下下面代码, session1.php 文件 <?php ini_set('session.save_p ...

  3. Linux动态共享库

    Linux操作系统上面的动态共享库大致分为三类:   一.操作系统级别的共享库和基础的系统工具库 libc.so, libz.so, libpthread.so等等,这些系统库会被放在/lib和/us ...

  4. Apache模块开发

    一.简介 Apache HTTP服务器是一个模块化的软件,使管理者可以选择核心中包含的模块以裁剪功能.可以在编译时选择被静态包含进httpd二进制映象的模块,也可以编译成独立于主httpd二进制映象的 ...

  5. program by the way......

    ostrich birds fruit apple constructor height weight method overload override base sub inherit extend ...

  6. tp5.1注册路由后接收不到参数

  7. js函数在frame中的相互调用详解

    原文章:http://www.jb51.net/article/47557.htm   一个HTML页面可以有一个或多个子框架,这些子框架以<iframe>来标记,用来显示一个独立的HTM ...

  8. Fibonacci number

    https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...

  9. 2018.10.15 loj#6013. 「网络流 24 题」负载平衡(费用流)

    传送门 费用流sb题. 直接从sss向每个点连边,容量为现有物品量. 然后从ttt向每个点连边,容量为最后库存量. 由于两个点之间可以互相任意运送物品,因此相邻的直接连infinfinf的边就行了. ...

  10. 2018.09.07 bzoj1911: [Apio2010]特别行动队(斜率优化dp)

    传送门 斜率优化dp经典题. 题目中说的很清楚,设f[i]表示前i个数分配出的最大值. 那么有: f[i]=max(f[j]+A∗(sum[i]−sum[j])2+B∗(sum[i]−sum[j])+ ...