mvc 读写txt文档
-----------------写入内容----------------
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文档的更多相关文章
- C# 将内容写入txt文档
<1> FileStream fs = new FileStream(@"D:\text.txt", FileMode.Append); StreamWriter s ...
- QTP操作txt文档
QTP可以在txt文件(文本文件中读取数据) 首先创造一个文档对象 set fso = createObject("scripting.filesystemobject") 然后用 ...
- 利用IDL将一个txt文档拆分为多个
测试.txt文档,每47行的格式相同,通过代码每47行存为一个txt,txt文档命名为其第一行数据. 代码如下: file='G:\data\测试.txt' openr,lun,file,/Get_L ...
- 用matlab查找txt文档中的关键字,并把关键字后面的数据存到起来用matlab处理
用matlab查找txt文档中的关键字,并把关键字后面的数据存到起来用matlab处理 我测了一组数据存到txt文件中,是个WIFI信号强度文档,里面有我们需要得到的数据,有没用的数据,想用matla ...
- WebService 实现BS环境与BS环境传递参数,根据参数生成txt文档
客户端: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Client.as ...
- C#操作Xml:通过XmlDocument读写Xml文档
什么是Xml? Xml是扩展标记语言的简写,是一种开发的文本格式.关于它的更多情况可以通过w3组织了解http://www.w3.org/TR/1998/REC-xml-19980210.如果你不知道 ...
- 将txt文档按行分割
昨天遇到了一个需求,需要将txt文档按行分割,并指定了行数, 最近在用python,就在网上搜了一下,在参考了http://blog.csdn.net/zhang_red/article/detail ...
- 用C++向一个txt文档中写数据
bool CMaked::WriteFileMake(CString filePath, const char *isChange) { ofstream file; //filePath为该txt文 ...
- 一个简易的Python爬虫,将爬取到的数据写入txt文档中
代码如下: import requests import re import os #url url = "http://wiki.akbfun48.com/index.php?title= ...
随机推荐
- google thumbnailator
Thumbnailator 是一个优秀的图片处理的Google开源Java类库.处理效果远比Java API的好. 从API提供现有的图像文件和图像对象的类中简化了处理过程,两三行代码就能够从现有图片 ...
- 使用maven管理引入jdk1.8
需要在配置文件settings.xml中加入: <profile> <id>jdk-1.8</id> <activation> <activeBy ...
- mockito使用
mockito学习资料: http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html http://blog.csdn.net/sdy ...
- 大神真会玩~这组C4D动图,我都看了一整天!
来自法国的Guillaume Kurkdjian 擅长创作一些平面动态图像 每张都诉说了一个小笑话或者小故事 像个极其微型的小电影. 这些动图的灵感可能来自某个交通工具 或是某个悠闲的时光 也可能是生 ...
- centos / debian 安装iptables服务
debian: #使用可参考 https://www.debian.cn/archives/991 #配置文件位于 /etc/iptables #重新配置使用dpkg-reconfigure ipta ...
- 2018.09.23 atcoder Boxes and Candies(贪心)
传送门 一道挺有意思的贪心. 从1到n依次满足条件. 注意要特判第一个数已经大于x的情况. 但是如何贪心吃呢? 如果靠左的数没有越界,我们吃靠右的数. 原因是下一次靠右的数就会成为靠左的数,相当于多贡 ...
- 2018.07.04 POJ 1654 Area(简单计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...
- 2018.09.14 codeforces364D(随机化算法)
传送门 根据国家集训队2014论文集中胡泽聪的随机化算法可以通过这道题. 对于每个数,它有12" role="presentation" style="posi ...
- 2018.08.28 codeforces600E(dsu on tree)
传送门 一道烂大街的dsu on tree板题. 感觉挺有趣的^_^ 代码真心简单啊! 就是先处理轻儿子,然后处理重儿子,其中处理轻儿子后需要手动消除影响. 代码: #include<bits/ ...
- Mysql字符串字段判断是否包含某个字符串的3种方法[转载]
方法一: SELECT * FROM users WHERE emails like "%b@email.com%"; 方法二: 利用mysql字符串函数 find_in_set( ...