在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
http://www.cnblogs.com/liuxinls/archive/2013/02/15/2912968.html
流用于对IO处理 内存流与缓冲的使用举例:
MemoryStream memStream=new MemoryStream();
BufferedStream bufStream=new BufferedStream(memStream);
byte[] b=new byte[10];
for(int i=0;i<10;i++)
{
bufStream.WriteByte((byte)i);
}
bufStream.Position=0;
bufStream.Read(b,0,9);
for(int i=0;i<10;i++)
{
Console.WriteLine("读的值是:{0}",b[i]);
}
Console.WriteLine("值是:{0}",bufStream.ReadByte());
Console.ReadLine(); 文件流的使用
string s=Console.ReadLine();
FileStream fileStream=new FileStream(s,FileMode.OpenOrCreate);
BinaryWriter binStream=new BinaryWriter (fileStream);
for(int i=1;i<=10;i++)
{
binStream.Write((int)i);
}
binStream.Close();
fileStream.Close();
FileStream f=new FileStream(s,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
BinaryReader buf=new BinaryReader(f);
for(int i=1;i<10;i++)
{
Console.WriteLine("输出{0}",buf.ReadByte ()); //在vs2012中这样不能读出东西来
Console.WriteLine("输出{0}",Bur.ReadInt32());才行,因为int是32位的
} 文本流的使用
string fileName,s;
fileName=Console.ReadLine();
StreamWriter fn=new StreamWriter(fileName,true);
for(int i=1;i<10;i++)
{
s=Console.ReadLine();
fn.WriteLine(s);
}
fn.Close();
StreamReader fr=new StreamReader(fileName);
for(int i=1;i<10;i++)
{
s=fr.ReadLine();
Console.WriteLine(s);
}
fr.Close();
Console.ReadLine(); 字符串流的使用
using System.Text;
StringBuilder str=new StringBuilder(100,1000);
StringWriter sw=new StringWriter(str);
for(int i=1;i<5;i++)
{
sw.Write(Console.ReadLine());
}
sw.Close();
Console.WriteLine(sw.ToString());
StringReader sr=new StringReader(sw.ToString());
Console.WriteLine(sr.ReadLine());
Console.ReadLine(); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论