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 读写类对象的更多相关文章

  1. JAVA基础学习之流的简述及演示案例、用缓冲区方法buffer读写文件、File类对象的使用、Serializable标记接口(6)

    1.流的简述及演示案例输入流和输出流相对于内存设备而言.将外设中的数据读取到内存中:输入将内存的数写入到外设中:输出.字符流的由来:其实就是:字节流读取文字字节数据后,不直接操作而是先查指定的编码表. ...

  2. .net 流(Stream) - StreamWriter和StreamReader、BinaryReader和BinaryWriter

    转自:http://www.oseye.net/user/kevin/blog/86 一.StreamWriter和StreamReader 从上一篇博文可知文件流.内存流和网络流操作的都是字节,每次 ...

  3. 实用的WPF Xml的简易读写类以及用法示例

    转自:http://www.silverlightchina.net/html/study/WPF/2012/0808/17980.html 最近真是写博客写的不可收拾,今天再来一篇. 因为做一些程序 ...

  4. 利用Spring.Net技术打造可切换的分布式缓存读写类

    利用Spring.Net技术打造可切换的Memcached分布式缓存读写类 Memcached是一个高性能的分布式内存对象缓存系统,因为工作在内存,读写速率比数据库高的不是一般的多,和Radis一样具 ...

  5. BinaryReader和BinaryWriter的leaveOpen参数 z

    在.NET 4.5后,微软为BinaryWriter和BinaryReader类型的构造函数中加入了leaveOpen参数,当该参数为true后,BinaryReader或者BinaryWriter关 ...

  6. C++ 类对象和 指针的区别

    C++ 类对象和 指针的区别 C++ 类对象和 指针的区别 转自:http://blog.csdn.net/ym19860303/article/details/8557746 指针的情况 class ...

  7. Android 通过 Intent 传递类对象或list对象

    (转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...

  8. NSLog(@"%@",类对象); 默认输出类名

    NSLog()函数输出Objective-c对象时,输出的是该对象的description方法的返回值.也就是说,以下两行代码作用完全一样(假设p是指向任何对象的指针变量). NSLog(@" ...

  9. WPF整理-XAML构建后台类对象

    1.XAML 接触WPF的第一眼就是XAML---XAML是用来描绘界面的.其实不然! "Actually, XAML has nothing to do with UI. It's mer ...

随机推荐

  1. Struts2学习笔记1

     一.下载struts2.0.1 http://struts.apache.org/downloads.html,下载struts-2.0.1-all.zip,这个压缩包中包括了开发struts2所需 ...

  2. iOS之layout方法-layoutSubviews、layoutIfNeeded、setNeedsLayout

    下面列举下iOS layout的相关方法: layoutSubviews layoutIfNeeded setNeedsLayout setNeedsDisplay drawRect sizeThat ...

  3. CentOs6.8安装Git并安装oh my zsh

    (一)git安装 1.下载git2.4.9或其他版本 Index of /pub/software/scm/git git各个版本下载链接: https://www.kernel.org/pub/so ...

  4. 获取select下拉列表选中的值

    html: <select id="resultList"> <option >1班</option> <option >2班< ...

  5. ACM——2的n次方

    2的N次方 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte 总提交:1715            测试通过:838 描述 编程精确计算2 ...

  6. js 函数命名

    1 函数命名可以使用匿名: var f=function(x){return x*2;} 2 可以使用变量: function double(x){return x*2;} 二者区别:后者会绑定到与其 ...

  7. aptitude

    aptitude比apt-get 要好用.是 Debian 及其衍生系统中功能极其强大的包管理工具.与 apt-get 不同的是,aptitude在处理依赖问题上更佳一些.举例来说,aptitude在 ...

  8. C++学习笔记3—对话框

    1.模态对话框 CTipDlg tipDlg; INT_PTR nResponse = tipDlg.DoModal(); if(nResponse == IDCANCEL) {  return; } ...

  9. swing容器继承重绘问题解决

    swing容器继承重绘问题解决   以JPanel为例,继承JPanel,想动态为器更换背景,这就涉及到重绘问题.一下是本人重写代码: package ui; import java.awt.Grap ...

  10. 访问 HTML中元素的方法

    http://www.w3school.com.cn/jsref/index.asp   1.document.getElementbyId("id1"),Html中,名称是id1 ...