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 ...
随机推荐
- 前缀、中缀、后缀表达式及其相互转化的Java实现
一.中缀表达式转换为前缀.后缀表达式 给个中缀表达式:a+b*c-(d+e) 首先根据运算符的优先级给所有运算单位加括号:((a+(b*c))-(d+e)) 将运算符号移动到对应括号的前面 ...
- 机器学习算法-K-means聚类
引文: k均值算法是一种聚类算法.所谓聚类.他是一种无监督学习,将类似的对象归到同一个蔟中.蔟内的对象越类似,聚类的效果越好. 聚类和分类最大的不同在于.分类的目标事先已知.而聚类则不一样. 由于其产 ...
- 【剑指offer】包括min函数的栈
转载请注明出处:http://blog.csdn.net/ns_code/article/details/26064213 剑指offer上的第21题,之前在Cracking the Coding i ...
- ArrayList的实现原理--转
1. ArrayList概述: ArrayList是List接口的可变数组的实现.实现了所有可选列表操作,并允许包括 null 在内的所有元素.除了实现 List 接口外,此类还提供一些方法来操作内部 ...
- [转] Android:微信授权登录与微信分享全解析
https://wohugb.gitbooks.io/wechat/content/qrconnent/refresh_token.html http://blog.csdn.net/xiong_it ...
- last_9t's_ramsey
cannot finish his face
- iOS tableview 静态表布局纪录
今天使用了tableview静态表布局,纪录如下 1:使用tableview 静态表,必须是UITableViewController 2:Content 中选择 Static Cells 如下图 3 ...
- Java 计算文件大小
long available = (long)getAttachmentContent(att.getId()).available(); public static String bytesTr ...
- PHP 获取当前日期的上个月的日期
获取当前日期的上个月的日期 <?php /** *参考有: *http://www.oschina.net/code/snippet_96541_4015 *http://stackoverfl ...
- Oracle删除多张表
项目中遇到要删除多张表,发现不能同时删除,可以先查询出SQL语句,然后批量执行 1.查询出SQL语句: select 'drop table '||table_name || ';' from use ...