BinaryReader 和BinaryWriter 读写类对象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; namespace ConsoleApplication1
{ public class INFO
{
public Int32 a { get; set; }
public string b { get; set; }
public string c { get; set; } public INFO()
{
a = ;
b = "";
c = "";
} public void ReadFromStream(Stream ms)
{ BinaryReader binReader = new BinaryReader(ms);
this.a = binReader.ReadInt32();
this.b = binReader.ReadString();
this.c = binReader.ReadString();
} public void WriteToStream(Stream ms)
{
BinaryWriter binWriter = new BinaryWriter(ms);
binWriter.Write(this.a);
binWriter.Write(this.b);
binWriter.Write(this.c); Console.WriteLine(this.a.ToString());
Console.WriteLine(this.b);
Console.WriteLine(this.c); } static void Main(string[] args)
{ const string FilePath = @"D:\a.txt";
FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
INFO g = new INFO();
g.a = ;
g.b = "abcdefa";
g.c = "小圆子"; g.WriteToStream(fs); fs.Close(); FileStream fsr = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
g.ReadFromStream(fsr);
fsr.Close();
Console.ReadLine();
}
} }
BinaryReader 和BinaryWriter 读写类对象的更多相关文章
- JAVA基础学习之流的简述及演示案例、用缓冲区方法buffer读写文件、File类对象的使用、Serializable标记接口(6)
1.流的简述及演示案例输入流和输出流相对于内存设备而言.将外设中的数据读取到内存中:输入将内存的数写入到外设中:输出.字符流的由来:其实就是:字节流读取文字字节数据后,不直接操作而是先查指定的编码表. ...
- .net 流(Stream) - StreamWriter和StreamReader、BinaryReader和BinaryWriter
转自:http://www.oseye.net/user/kevin/blog/86 一.StreamWriter和StreamReader 从上一篇博文可知文件流.内存流和网络流操作的都是字节,每次 ...
- 实用的WPF Xml的简易读写类以及用法示例
转自:http://www.silverlightchina.net/html/study/WPF/2012/0808/17980.html 最近真是写博客写的不可收拾,今天再来一篇. 因为做一些程序 ...
- 利用Spring.Net技术打造可切换的分布式缓存读写类
利用Spring.Net技术打造可切换的Memcached分布式缓存读写类 Memcached是一个高性能的分布式内存对象缓存系统,因为工作在内存,读写速率比数据库高的不是一般的多,和Radis一样具 ...
- BinaryReader和BinaryWriter的leaveOpen参数 z
在.NET 4.5后,微软为BinaryWriter和BinaryReader类型的构造函数中加入了leaveOpen参数,当该参数为true后,BinaryReader或者BinaryWriter关 ...
- C++ 类对象和 指针的区别
C++ 类对象和 指针的区别 C++ 类对象和 指针的区别 转自:http://blog.csdn.net/ym19860303/article/details/8557746 指针的情况 class ...
- Android 通过 Intent 传递类对象或list对象
(转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...
- NSLog(@"%@",类对象); 默认输出类名
NSLog()函数输出Objective-c对象时,输出的是该对象的description方法的返回值.也就是说,以下两行代码作用完全一样(假设p是指向任何对象的指针变量). NSLog(@" ...
- WPF整理-XAML构建后台类对象
1.XAML 接触WPF的第一眼就是XAML---XAML是用来描绘界面的.其实不然! "Actually, XAML has nothing to do with UI. It's mer ...
随机推荐
- 读取xml格式文件
$v = [xml]get-content d:\vmconfig.xml $v.Domain.Computer.Name =========================== $v.GetElem ...
- Android-怎样用命令行进行打包
转载请标明出处:http://blog.csdn.net/goldenfish1919/article/details/40978859 1.生成R文件 aapt package -f -m -J . ...
- mac上SVN项目管理,提示被锁定的解决方法
问题 mac上SVN项目管理,提示被锁定.不能commit.也不能update.提示 clean the working copy and then. .. 解决方法 watermark/2/text ...
- iOS之定位与地图
概览 现在很多社交.电商.团购应用都引入了地图和定位功能,似乎地图功能不再是地图应用 和导航应用所特有的.的确,有了地图和定位功能确实让我们的生活更加丰富多彩,极大的改变了我们的生活方式.例如你到了一 ...
- struts----通配符设置
本次学习的内容是struts通配符配置: 具体内容为: 一.准备工作 1.新建Web工程 2.添加struts:右键点击工程名选择My Eclipse-->点击add struts..--> ...
- Linux性能实时监测工具netdata安装配置
netdata:功能强大的实时性能检测工具,展示地址. github地址:https://github.com/firehol/netdata 本文介绍在CentOS 6.7下安装netdata 1. ...
- Spring-data-redis操作redis cluster
Redis 3.X版本引入了集群的新特性,为了保证所开发系统的高可用性项目组决定引用Redis的集群特性.对于Redis数据访问的支持,目前主要有二种方式:一.以直接调用jedis来实现:二.使用sp ...
- 处理 eclipse 导入报错 Invalid project description,问题
有时候在添加工程时,会出现如图所示的错误信息, ,提示显示将要添加的工程已经存在,但是在工作空间里却找不到,这个时候,要做就是, 在导入的时候选择General->Existing Projec ...
- ThinkPHP函数详解:I方法
ThinkPHP的I方法是3.1.3版本新增的,如果你是之前的3.*版本的话,可以直接参考使用3.1快速入门教程系列的变量部分. 概述 正如你所见到的一样,I方法是ThinkPHP众多单字母函数中的新 ...
- java 正则表达式匹配字符串
private static List<String> getImage(String str){ List<String> tmp=new ArrayList<Stri ...