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 ...
随机推荐
- [转]Unity批量制作预制物体Prefab
http://www.u3dblog.com/?p=441 有时候场景中一大批物体都需要制作成预制物体,但是unity只能手动一个一个的创建,感觉非常的蹩脚,下面一个编辑器类的方法解决你的麻烦. st ...
- kontalk
Site: http://kontalk.org/ Code: https://github.com/kontalk/androidclient
- android89 服务service
#服务 服务不能new,new出来的只是一个普通java对象不是服务,只能够通过Intent和startService(intent)创建服务. ###开启方式 * startService,onCr ...
- (原创)speex与wav格式音频文件的互相转换(二)
之前写过了如何将speex与wav格式的音频互相转换,如果没有看过的请看一下连接 http://www.cnblogs.com/dongweiq/p/4515186.html 虽然自己实现了相关的压缩 ...
- android 中 系统日期时间的获取
import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ...
- 自己写的demo---equals()跟==的区别
package equals; /*public class equals { //基本数据类型跟引用数据类型(复合数据类型), //在引用数据类型中equals方法被重写,一般用来比较内存地址 pu ...
- Unity3D 之2D动画机
这里来讲解一下2D动画机的使用 2D的时候,默认的情况下,可以调用默认的站立之类的动画,然后通过触发,可以变化自己的动画. 一:将一个图切成一些一个元素 二:创建一个精灵,给精灵添加一个动画机 三:给 ...
- java Spring 在WEB应用中的实例化
.前面讲解的都是通过直接读取配置文件,进行的实例化ApplicationContext AbstractApplicationContext app = new ClassPathXmlApplica ...
- 关于ligerui 中 grid 表格的扩展搜索功能在远程数据加载时无法使用的解决办法
要想使用grid里的扩展搜索功能,除了要引用ligerui主要的js文件外,还必须引入下面的JS文件: 1.Source\demos\filter\ligerGrid.showFilter.js 2. ...
- spring mvc源码解析
1.从DispatcherServlet开始 与很多使用广泛的MVC框架一样,SpringMVC使用的是FrontController模式,所有的设计都围绕DispatcherServlet 为中心来 ...