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= ...
随机推荐
- [leetcode]238. Product of Array Except Self除了自身以外的数组元素乘积
Given an array nums of n integers where n > 1, return an array output such that output[i] is equ ...
- 22-maven-安装与配置
转载:https://blog.csdn.net/wy727764020/article/details/80595451 Maven的安装以及eclipse中配置maven 2018年06月06日 ...
- Sql自定义表类型批量导入数据
-- 创建自定义表类型 CREATE TYPE [dbo].[App_ProductTable] AS TABLE( [p_name] [varchar](50) NOT NULL, [p_audio ...
- PL/Sql快速执行 insert语句的.sql文件
当全是 insert语句的.sql文件太大时(insert 语句条数太大),直接打开执行sql文件,pl/sql会卡死. 这是可以用pl/sql的命令窗口来执行.sql文件,操作步骤如下: 1.新建命 ...
- c++ 对象复制引用时何时调用构造函数、析构函数
class TEST{ private : public : TEST() {std::cout << "constructor" << std::endl ...
- 设计模式-生成者模式之c#代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 主频3.0 1g内存是什么意思
我会讲解一些常用的计算机应用知识.希望大家多多支持,稍后更新,我的技术水平在国内属于顶尖的水平,不服来战...稍后更新...
- CSS 关键的基础知识
今晚看了 百度传课 一门关于CSS的课程, 感觉不错, 随手记了点儿笔记, 供以后查阅. =================================================== pos ...
- 2018.09.25 bzoj1856: [Scoi2010]字符串(组合数学)
传送门 如果有n==m的条件就是卡特兰数. 但现在n不一定等于m. 我们可以考虑用求卡特兰数一样的方法来求答案. 我们知道有一种求卡特兰数的方法是转到二维平面求答案. 这道题就可以这样做. 我们将这个 ...
- 2018.07.31洛谷P1552 [APIO2012]派遣(可并堆)
传送门 貌似是个可并堆的模板题,笔者懒得写左偏堆了,直接随机堆水过.实际上这题就是维护一个可合并的大根堆一直从叶子合并到根,如果堆中所有数的和超过了上限就一直弹直到所有数的和不超过上限为止,最后对于当 ...