社区
VB
帖子详情
MemoryStream中flush方法有什么作用
lixiaocai123
2010-12-10 03:28:46
今天刚接触到MemoryStream
里面flush方法有什么作用,请各位大侠帮帮忙
...全文
622
2
打赏
收藏
MemoryStream中flush方法有什么作用
今天刚接触到MemoryStream 里面flush方法有什么作用,请各位大侠帮帮忙
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
lixiaocai123
2010-12-10
打赏
举报
回复
楼上意思,这个方法什么都没有执行么?
兔子-顾问
2010-12-10
打赏
举报
回复
http://msdn.microsoft.com/zh-cn/library/system.io.memorystream.flush(v=VS.80).aspx
重写 Stream.Flush 以便不执行任何操作。
因为继承自Stream,所以重写了这个方法实际没执行任何代码,流中 Flush 的意义是把缓存数据写入实际的流设备,文件流的做法就是写文件。memorystream则忽略次方法。不需要调用。
XmlReader 读取器读取内存流
Memory
Stream
的注意事项
Memory
Stream
对象提供了无需进行IO就可以创建
Stream
的
方法
,XmlTextWriter和XmlReader提供快速书写和读取XML内容的
方法
,结合
Memory
Stream
,就可以直接在内存
中
构造XmlTextWriter,并用XmlReader进行读取。 使用
Memory
Stream
和XmlTextWriter进行书写XML,需要注意两点:XmlTextWriter.
Flush
操作和重设
Memory
Stream
.Position = 0。 C# <%@ Page Language=”C#”%> <%@ Import Namespace=”System.Xml” %>
MD5加密解密
MD5 加密 解密 public string EnCode(string data) { byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = cryptoProvider.KeySize;
Memory
Stream
ms = new
Memory
Stream
(); Crypto
Stream
cst = new Crypto
Stream
(ms, cryptoProvider.CreateEncryptor(byKey,byIV), Crypto
Stream
Mode.Write);
Stream
Writer sw = new
Stream
Writer(cst); sw.Write(data); sw.
Flush
(); cst.
Flush
FinalBlock(); sw.
Flush
(); return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); }
shp转换为KML+源代码
shp2kml+源代码 public byte[] ToKML() {
Memory
Stream
ms = new
Memory
Stream
();
Stream
Writer sw = new
Stream
Writer(ms); XmlTextWriter kml = new XmlTextWriter(sw); //kml.Namespaces = true; kml.Formatting = Formatting.Indented; kml.WriteStartDocument(); kml.WriteStartElement("kml"); kmlRoot.ToKML(kml); kml.WriteEndElement(); kml.WriteEndDocument(); kml.
Flush
(); kml.Close(); return ms.ToArray(); }
C#加密JAVA解密
C# 加密 JAVA 解密源码 using System; using System.IO; using System.Security.Cryptography; namespace WindowsApplication1 { /// /// Security 的摘要说明。 /// public class Security { const string KEY_64 = "flxmtdes"; const string IV_64 = "flxmtIvS"; public Security() { // // TODO: 在此处添加构造函数逻辑 // } public static string Encode(string data) { byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = cryptoProvider.KeySize;
Memory
Stream
ms = new
Memory
Stream
(); Crypto
Stream
cst = new Crypto
Stream
(ms, cryptoProvider.CreateEncryptor(byKey, byIV), Crypto
Stream
Mode.Write);
Stream
Writer sw = new
Stream
Writer(cst); sw.Write(data); sw.
Flush
(); cst.
Flush
FinalBlock(); sw.
Flush
(); return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); } public static string Decode(string data) { byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); byte[] byEnc; try { byEnc = Convert.FromBase64String(data); } catch { return null; } DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
Memory
Stream
ms = new
Memory
Stream
(byEnc); Crypto
Stream
cst = new Crypto
Stream
(ms, cryptoProvider.CreateDecryptor(byKey, byIV), Crypto
Stream
Mode.Read);
Stream
Reader sr = new
Stream
Reader(cst); return sr.ReadToEnd(); } } }
Stream
.Write 与
Stream
Writer.Write 的不同
一、测试
方法
是否结果相同首先看下面两段代码1是
Stream
Writer.Write 2是
Stream
.Write: 1 代码如下:
Stream
ms = new
Memory
Stream
();string str = “这是测试字符串”;
Stream
Writer sw = new
Stream
Writer(ms, Encoding.UTF8);sw.Write(str);sw.
Flush
(); 2 代码如下:
Stream
ms = new
Memory
Stream
();string str = “这是测试字符串”;byte[] buffer = Encoding.UTF8.GetBytes(s
VB
16,555
社区成员
110,528
社区内容
发帖
与我相关
我的任务
VB
VB技术相关讨论,主要为经典vb,即VB6.0
复制链接
扫一扫
分享
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章