操作流

//1.普通写法
//2.忽略字节的写法
//3.忽略转换的写法
None.gif              using  (Stream stream  =   new  MemoryStream())
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                
byte[] bytes1 = UnicodeEncoding.Unicode.GetBytes(s);
InBlock.gif                
byte[] bytes2 = BitConverter.GetBytes(n);
InBlock.gif                stream.Write(bytes1, 
0, bytes1.Length);
InBlock.gif                stream.Write(bytes2, 
0, bytes2.Length);
InBlock.gif
InBlock.gif                stream.Seek(
0, SeekOrigin.Begin);
InBlock.gif                
byte[] bytes3 = new byte[stream.Length - 4];
InBlock.gif                
byte[] bytes4 = new byte[4];
InBlock.gif                stream.Read(bytes3, 
0, bytes3.Length);
InBlock.gif                stream.Read(bytes4, 
0, bytes4.Length);
InBlock.gif
InBlock.gif                MessageBox.Show(UnicodeEncoding.Unicode.GetString(bytes3)
+"  "+BitConverter.ToInt32(bytes4,0));
InBlock.gif                
//====================================================
InBlock.gif
                StreamWriter writer = new StreamWriter(stream);
InBlock.gif                writer.WriteLine(s);
InBlock.gif                writer.WriteLine(n);
InBlock.gif                writer.Flush();
InBlock.gif                stream.Seek(
0, SeekOrigin.Begin);
InBlock.gif
InBlock.gif                StreamReader reader 
= new StreamReader(stream);
InBlock.gif                
string s2 = reader.ReadLine();
InBlock.gif                
int n2 = int.Parse(reader.ReadLine);
InBlock.gif                
//=========================================================
InBlock.gif
                BinaryWriter writer = new BinaryWriter(stream);
InBlock.gif                writer.Write(s);
InBlock.gif                writer.Write(n);
InBlock.gif                writer.Flush();
InBlock.gif                stream.Seek(
0,SeekOrigin.Begin);
InBlock.gif                BinaryReader reader 
= new BinaryReader(stream);
InBlock.gif                
string s2 = reader.ReadString();
InBlock.gif                
int n2 = reader.ReadInt32();
InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif            }
posted on 2006-12-31 17:43 吴勇 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wuyong/archive/2006/12/31/609115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值