FileStream fsRead = new FileStream(@"C:\Users\Administrator\Desktop\u.html",FileMode.OpenOrCreate,FileAccess.Read);
byte[] buffer = new byte[ * * ];
//返回本次读取到的有效字节数
int iNr= fsRead.Read(buffer, , buffer.Length);
//将字节数组中每一个元素按指定编码写成字符串
string str =Encoding.UTF8.GetString(buffer,,iNr);
Console.WriteLine(str); //关闭文件
fsRead.Close();
//释放资源
fsRead.Dispose(); Console.ReadKey(); //可以自动释放和关闭资源
using (FileStream fsWrite = new FileStream(@"C:\Users\Administrator\Desktop\u.html", FileMode.OpenOrCreate, FileAccess.Write))
{
string strN = "看我把你覆盖掉";
byte[] buf = Encoding.UTF8.GetBytes(strN);
fsWrite.Write(buf, , buf.Length);
Console.WriteLine("写入成功");
}
Console.ReadKey();

FileStream操作文件读写的更多相关文章

  1. 16 IO操作文件读写

    IO的分类 第一种分法: 1.输入流 2.输出流 第二种分法: 1.字节流 2.字符流 第三种分法: 1.节点流 2.处理流 I/O当中的核心类: InputStream  <--------F ...

  2. FileStream 操作文件复制

    static void Main(string[] args) { string source = @"D:\c\集合.avi"; string target = @"C ...

  3. 【转】Android SDCard操作(文件读写,容量计算)

    android.os.Environment 提供访问环境变量 java.lang.Object     android.os.Environment   Environment 静态方法: 方法 : ...

  4. 字符编码和Python代码操作文件

    字符编码和Python代码操作文件 读写模式之a模式 # a模式 只追加模式 # 路径不存在:自动创建 with open(r'a.txt','a',encoding='utf8') as f: pa ...

  5. c#FileStream文件读写(转)

    FileStream对象表示在磁盘或网络路径上指向文件的流.这个类提供了在文件中读写字节的方法,但经常使用StreamReader或StreamWriter执行这些功能.这是因为FileStream类 ...

  6. .net对文件的操作之文件读写

    读写文件的步骤一般需要5步: 创建文件流 创建读写器 执行读或写的操作 关闭读写器 关闭文件流 需要引用:System.IO这个命名空间 代码演示: string path = @"F:\a ...

  7. File FileStream StreamWriter StreamReader文件读写操作方法

    string path = "D:\\AccountChecking\\Test.txt"; string content = "abcdefg\r\nhigklmn\r ...

  8. 问题:C#打开一个文本文档往里面写数据,没有就新建文档 ;结果:c#FileStream文件读写(转)

    FileStream对象表示在磁盘或网络路径上指向文件的流.这个类提供了在文件中读写字节的方法,但经常使用StreamReader或 StreamWriter执行这些功能.这是因为FileStream ...

  9. c#FileStream文件读写

    //C#文件流写文件,默认追加FileMode.Append             string msg = "okffffffffffffffff";            b ...

随机推荐

  1. getAttribute:取得属性; setAttribute:设置属性。

    input.setAttribute("title"); 当它是一个值,就是取值. input.setAttribute("title", "hell ...

  2. PHP连续签到

    require "./global.php"; $act = isset($_GET['act']) ? $_GET['act'] : "error"; // ...

  3. Symfony2目录结构说明

    了解框架的目录结构是框架快速入门的一个途径,一个成熟的框架,每个功能模块都被划分存放在不同的目录. Symfony2一级目录结构: ├── app //这目录下包含了,配置文件(应用的配置文件会被im ...

  4. 文成小盆友python-num11-(2) python操作Memcache Redis

    本部分主要内容: python操作memcache python操作redis 一.python 操作 memcache memcache是一套分布式的高速缓存系统,由LiveJournal的Brad ...

  5. 信息安全实验二:return-to-libc

    title: return-to-libc date: 2016-01-11 17:40:30 categories: information-security tags: return-to-lib ...

  6. 转:Spine.JS+Rails重客户端Web应用技术选型思路:『风车』架构设计

    原文来自于:http://www.infoq.com/cn/articles/fengche-co-architecture 风车这个项目开始于 2011 年 11 月份,之前叫做 Pragmatic ...

  7. UNIQUE NullAble

    一般情况 UNIQUE 不应该出现nullable的 但是如果我们要支持也是有办法的,就是写一个filter. https://msdn.microsoft.com/en-us/library/ms1 ...

  8. hdu 1543 Paint the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...

  9. c++封装性

    C++ code到运行程序 作为一个c++程序员这个应该是最应该知道的细节,简言之:编译----链接----可执行的程序.这里所说的细节主要是第一步的细节,编译器如何把c++代码编译成目标代码.概括的 ...

  10. COJ 1010 WZJ的数据结构(十) 线段树区间操作

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1001 WZJ的数据结构(十) 难度级别:D: 运行时间限制:3000ms: ...