ASP.NET 文件操作类
1.读取文件
2.写入文件
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml; namespace BigData.Common.File
{
/// <summary>
/// 文件操作类
/// </summary>
public class FileHelper
{
/// <summary>
/// 写入一行数据
/// </summary>
/// <param name="path"></param>
/// <param name="str"></param>
/// <param name="isAppend"></param>
/// <returns></returns>
public static bool WriteLine(string path, string str, bool isAppend = true)
{
try
{
StreamWriter sw = new StreamWriter(path, isAppend);
sw.WriteLine(str);
sw.Flush();
sw.Close();
}
catch (Exception)
{
return false;
} return true;
} /// <summary>
/// 读取文件所有内容
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string ReadAll(string path)
{
string result = string.Empty;
try
{
StreamReader sr = new StreamReader(path);
result = sr.ReadToEnd();
sr.Close();
}
catch (Exception)
{
return string.Empty;
} return result;
} /// <summary>
/// 写入文本
/// </summary>
/// <param name="path"></param>
/// <param name="str"></param>
/// <returns></returns>
public static bool WriteToTxt(string path, string str)
{
try
{
FileStream fs = new FileStream(path, FileMode.Append);
byte[] bs = Encoding.Default.GetBytes(str);
fs.Write(bs, , bs.Length);
fs.Flush();
fs.Close();
}
catch (Exception)
{
return false;
} return true;
} /// <summary>
/// 读取文本
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string ReadTxt(string path)
{
string result = string.Empty;
try
{
FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
byte[] bs = new byte[fs.Length];
fs.Read(bs, , bs.Length);
result = Encoding.Default.GetString(bs);
fs.Close();
}
catch (Exception)
{
return string.Empty;
} return result;
}
}
}
ASP.NET 文件操作类的更多相关文章
- asp.net文件操作类
/** 文件操作类 **/ #region 引用命名空间 using System; using System.Collections.Generic; using System.Text; usin ...
- [C#] 常用工具类——文件操作类
/// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在&l ...
- 文件操作类CFile
CFile file; CString str1= L"写入文件成功!"; wchar_t *str2; if (!file.Open(L"Hello.txt" ...
- android 文件操作类简易总结
android 文件操作类(参考链接) http://www.cnblogs.com/menlsh/archive/2013/04/02/2997084.html package com.androi ...
- Ini文件操作类
/// <summary> /// Ini文件操作类 /// </summary> public class Ini { // 声明INI文件的写操作函数 WritePriva ...
- java csv 文件 操作类
一个CSV文件操作类,功能比较齐全: package tool; import java.io.BufferedReader; import java.io.BufferedWriter; impor ...
- Qt5:Qt文件操作类 QFile
在QT中,操作文件一般不使用C++提供的文件操作类 , 因为操作文件的时候,要用到C++提供的 string 类,而在QT中使用的是Qt自己实现的一个string类 QString .在Qt中使用C+ ...
- C# 文件操作类大全
C# 文件操作类大全 时间:2015-01-31 16:04:20 阅读:1724 评论:0 收藏:0 [点我收藏+] 标签: 1.创建文件夹 //usin ...
- Java文件操作类效率对比
前言 众所周知,Java中有多种针对文件的操作类,以面向字节流和字符流可分为两大类,这里以写入为例: 面向字节流的:FileOutputStream 和 BufferedOutputStream 面向 ...
随机推荐
- Vue 系列之 渲染与事件处理
渲染相关 列表渲染 与 条件渲染 Vue 中的常见的渲染有 列表渲染 和 条件渲染 所谓条件渲染,则是通过添加一定的逻辑条件来进行 Dom 元素的操作 v-if v-else v-else-if &l ...
- vue项目导入外部css样式和js文件
<template> <div id="app" > </div> </template> <script src=" ...
- Scoop及使用
scoop window的命令行安装程序管理工具 通常我们下载软甲需要从网上搜索软件并下载安装等一系列复杂麻烦的过程 现在有了scoop 等一系列包管理器的诞生,就是省去了上述繁琐的搜索 - 下载 - ...
- 不要拿ERP的报表忽悠领导!——一个报表引发的企业经营反思
文 | 帆软数据应用研究院船长 本文出自:知乎专栏<帆软数据应用研究院>——数据干货&资讯集中地 领导的经营决策能只依赖于ERP报表吗? 不能! 1. ERP报表个性化不足:企业经 ...
- Oracle 11g数据库详细安装过程
1.Oracle 11g下载 官方网址为:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.h ...
- SG Input 软件安全分析之逆向分析
前言 通过本文介绍怎么对一个 windows 程序进行安全分析.分析的软件版本为 2018-10-9 , 所有相关文件的链接 链接:https://pan.baidu.com/s/1l6BuuL-HP ...
- 我的博客:C# PHP J2ee Java Android js WP Asp.net mvc Python
<p><A target="_blank" href="http://blog.163.com/hr_company_product/" &g ...
- 慕学在线网0.2_users表设计(2)
接着上一篇,我们继续对users表进行完善.其中包括邮箱验证码(EmailVerifyRecord)和轮播图(PageBanner)两个model. 1.编写"models.py" ...
- asp.net根据参数找不到记录后响应404及显示错误页
在asp.net mvc 中,action方法里根据参数获取数据,假如获取的数据为空,为了响应404错误页,我们可以return HttpNotFound(); 但是在asp.net webform中 ...
- 17秋 软件工程 团队第五次作业 Alpha Scrum8
17秋 软件工程 团队第五次作业 Alpha Scrum8 今日完成的任务 世强:部门人员管理界面设计编写: 港晨:设计主页面: 树民:web后端框架与前端对接: 伟航:app前端界面的美工: 陈翔: ...