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

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. VR

  2. Algorithmic Trading[z]

    Algorithmic Trading has been a hot topic for equity/derivative trading over a decade. Many ibanks an ...

  3. 20172325 2017-2018-2 《Java程序设计》第六周学习总结

    20172325 2017-2018-2 <Java程序设计>第六周学习总结 教材学习内容总结 1.利用[ ]建立一个数组,整列数据可以通过数组名引用,数组中的每个元素则可以通过其在数组中 ...

  4. SECURITY_ATTRIBUTES 实现最低权限总结

    SetSecurityDescriptorDacl函数可以用来设置DACL中的信息.如果一个DACL已经在security descriptor中存在,那么此DACL将被替换.值得注意的是MSDN中的 ...

  5. Mina 系列(二)之基础

    Mina 系列(二)之基础 Mina 使用起来多么简洁方便呀,就是不具备 Java NIO 的基础,只要了解 Mina 常用的 API,就可以灵活使用并完成应用开发. 1. Mina 概述 首先,看 ...

  6. 打开jsp页面时,显示空白页。

    打开jsp页面时,显示空白页.   #foreach($e in $listPlanItem)          #set($listPlanDetail=$!e.get(2))        < ...

  7. [开源,学习,分享]UWP第三方简书客户端分享

    简介 Windows10正式版发布到现在,我利用零零碎碎的一些时间对UWP进行一些学习,也基于这门技术开发了一个第三方的简书App. 基本界面 优酷视频: http://v.youku.com/v_s ...

  8. const当做标记的函数重载,但是仅仅是限于类里面的成员函数

    (1)我们知道函数的重载时根据函数的参数类型以及函数参数个数来重载的,不能用函数返回值来重载函数.但是有时候函数参数个数和函数参数类型重载函数会和默认参数发生冲突: int fun(int i,cha ...

  9. Django入门指南-第8章:第一个测试用例(完结)

    python manage.py test python manage.py test --verbosity=2 # boards/tests.py from django.core.urlreso ...

  10. arduino 串口命令解析

    /* DS3231_test.pde Eric Ayars 4/11 Test/demo of read routines for a DS3231 RTC. Turn on the serial m ...