支持查找。不过这个特性在其某些子类中就不支持,比如网络流。
继承Stream抽象类的子类有: System.Data.OracleClient.OracleBFile:表示托管 OracleBFile 对象,该对象的设计旨在与 Oracle BFILE 数据类型配合使用。 System.Data.OracleClient.OracleLob:表示存储在 Oracle 服务器上的大型对象二进制 (LOB) 数据类型。 System.IO.BufferedStream:给另一流上的读写操作添加一个缓冲层。 System.IO.Compression.DeflateStream:提供用于使用 Deflate 算法压缩和解压缩流的方法和属性。 System.IO.Compression.GZipStream:提供用于压缩和解压缩流的方法和属性。 System.IO.FileStream:公开以文件为主的 Stream,既支持同步读写操作,也支持异步读写操作。 System.IO.MemoryStream:创建其支持存储区为内存的流。 System.Net.Sockets.NetworkStream:提供用于网络访问的基础数据流。 System.Security.Cryptography.CryptoStream:定义将数据流链接到加密转换的流。
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace IODemo
- {
- /// <summary>
- /// 说明:基于字节的方式读写流的例子。
- /// 作者:周公
- /// 日期:2008-6-30
- /// 原文地址:http://blog.youkuaiyun.com/zhoufoxcn
- /// </summary>
- public class StreamDemo
- {
- private string fileName;
- /// <summary>
- /// 要进行读写的文件全路径
- /// </summary>
- public string FileName
- {
- get { return fileName; }
- set { fileName = value; }
- }
- /// <summary>
- /// 基于字节的方式写文件流
- /// </summary>
- /// <param name="message"></param>
- public void WriteFile(string message)
- {
- if (fileName != null)
- {
- FileInfo file = new FileInfo(fileName);
- FileStream stream = null;
- //将要写入的字符串转换成utf8编码的字节数组
- byte[] buffer = System.Text.Encoding.UTF8.GetBytes(message);
- if (!file.Exists)
- {
- //如果不存在指定文件则创建指定文件
- stream = file.Create();
- }
- else
- {
- //否则打开打开文件流
- stream = file.OpenWrite();
- }
- //将字符串转换的字节数组写入到流中
- stream.Write(buffer, 0, buffer.Length);
- stream.Close();//关闭流
- }
- else
- {
- throw new ArgumentNullException("没有指定文件名异常");
- }
- }
- /// <summary>
- /// 基于字节的方式读文件流
- /// </summary>
- /// <returns></returns>
- public string ReadMessage()
- {
- string result = string.Empty;
- if (fileName != null)
- {
- FileInfo file = new FileInfo(fileName);
- FileStream stream = file.OpenRead();
- byte[] buffer = new byte[(int)file.Length];
- stream.Read(buffer, 0, (int)(file.Length));
- //将读取到的字符串按照utf8方式转换成字符串
- result = System.Text.Encoding.UTF8.GetString(buffer);
- stream.Close();//关闭流
- }
- else
- {
- throw new ArgumentNullException("没有指定文件名异常");
- }
- return result;
- }
- }
- }
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace IODemo
{
/// <summary>
/// 说明:基于字节的方式读写流的例子。
/// 作者:周公
/// 日期:2008-6-30
/// 原文地址:http://blog.youkuaiyun.com/zhoufoxcn
/// </summary>
public class StreamDemo
{
private string fileName;
/// <summary>
/// 要进行读写的文件全路径
/// </summary>
public string FileName
{
get { return fileName; }
set { fileName = value; }
}
/// <summary>
/// 基于字节的方式写文件流
/// </summary>
/// <param name="message"></param>
public void WriteFile(string message)
{
if (fileName != null)
{
FileInfo file = new FileInfo(fileName);
FileStream stream = null;
//将要写入的字符串转换成utf8编码的字节数组
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(message);
if (!file.Exists)
{
//如果不存在指定文件则创建指定文件
stream = file.Create();
}
else
{
//否则打开打开文件流
stream = file.OpenWrite();
}
//将字符串转换的字节数组写入到流中
stream.Write(buffer, 0, buffer.Length);
stream.Close();//关闭流
}
else
{
throw new ArgumentNullException("没有指定文件名异常");
}
}
/// <summary>
/// 基于字节的方式读文件流
/// </summary>
/// <returns></returns>
public string ReadMessage()
{
string result = string.Empty;
if (fileName != null)
{
FileInfo file = new FileInfo(fileName);
FileStream stream = file.OpenRead();
byte[] buffer = new byte[(int)file.Length];
stream.Read(buffer, 0, (int)(file.Length));
//将读取到的字符串按照utf8方式转换成字符串
result = System.Text.Encoding.UTF8.GetString(buffer);
stream.Close();//关闭流
}
else
{
throw new ArgumentNullException("没有指定文件名异常");
}
return result;
}
}
}
- 基于字符的方式:
基于字符的方式:
- <PRE class=csharp name="code">using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace IODemo
- {
- /// <summary>
- /// 说明:基于字符的方式读写流的例子。
- /// 作者:周公
- /// 日期:2008-6-30
- /// 原文地址:http://blog.youkuaiyun.com/zhoufoxcn
- /// </summary>
- public class TextDemo
- {
- private string fileName;
- /// <summary>
- /// 要进行读写的文件全路径
- /// </summary>
- public string FileName
- {
- get { return fileName; }
- set { fileName = value; }
- }
- /// <summary>
- /// 基于字符的方式写文件流
- /// </summary>
- /// <param name="message"></param>
- public void WriteFile(string message)
- {
- if (fileName != null)
- {
- FileInfo file = new FileInfo(fileName);
- FileStream stream = null;
- StreamWriter writer = null;
- if (!file.Exists)
- {
- //如果不存在指定文件则创建指定文件
- stream = file.Create();
- }
- else
- {
- //否则打开打开文件流
- stream = file.OpenWrite();
- }
- writer = new StreamWriter(stream);
- //将字符串写入流中
- writer.Write(message);
- writer.Close();
- stream.Close();//关闭流
- }
- else
- {
- throw new ArgumentNullException("没有指定文件名异常");
- }
- }
- /// <summary>
- /// 基于字符的方式读文件流
- /// </summary>
- /// <returns></returns>
- public string ReadMessage()
- {
- string result = string.Empty;
- if (fileName != null)
- {
- FileInfo file = new FileInfo(fileName);
- FileStream stream = file.OpenRead();
- StreamReader reader = new StreamReader(stream);
- //一次性读入所有字符
- result = reader.ReadToEnd();
- reader.Close();
- stream.Close();//关闭流
- }
- else
- {
- throw new ArgumentNullException("没有指定文件名异常");
- }
- return result;
- }
- }
- }</PRE>
- using System;
-
- using System.Collections.Generic;
-
- using System.Text;
-
- using System.IO;
-
-
-
- namespace IODemo
-
- {
-
- /// <summary>
-
- /// 说明:基于字符的方式读写流的例子。
-
- /// 作者:周公
-
- /// 日期:2008-6-30
-
- /// 原文地址:http://blog.youkuaiyun.com/zhoufoxcn
-
- /// </summary>
-
- public class TextDemo
-
- {
-
- private string fileName;
-
- /// <summary>
-
- /// 要进行读写的文件全路径
-
- /// </summary>
-
- public string FileName
-
- {
-
- get { return fileName; }
-
- set { fileName = value; }
-
- }
-
- /// <summary>
-
- /// 基于字符的方式写文件流
-
- /// </summary>
-
- /// <param name="message"></param>
-
- public void WriteFile(string message)
-
- {
-
- if (fileName != null)
-
- {
-
- FileInfo file = new FileInfo(fileName);
-
- FileStream stream = null;
-
- StreamWriter writer = null;
-
- if (!file.Exists)
-
- {
-
- //如果不存在指定文件则创建指定文件
-
- stream = file.Create();
-
- }
-
- else
-
- {
-
- //否则打开打开文件流
-
- stream = file.OpenWrite();
-
- }
-
- writer = new StreamWriter(stream);
-
- //将字符串写入流中
-
- writer.Write(message);
-
- writer.Close();
-
- stream.Close();//关闭流
-
-
-
- }
-
- else
-
- {
-
- throw new ArgumentNullException("没有指定文件名异常");
-
- }
-
- }
-
- /// <summary>
-
- /// 基于字符的方式读文件流
-
- /// </summary>
-
- /// <returns></returns>
-
- public string ReadMessage()
-
- {
-
- string result = string.Empty;
-
- if (fileName != null)
-
- {
-
- FileInfo file = new FileInfo(fileName);
-
- FileStream stream = file.OpenRead();
-
- StreamReader reader = new StreamReader(stream);
-
- //一次性读入所有字符
-
- result = reader.ReadToEnd();
-
- reader.Close();
-
- stream.Close();//关闭流
-
-
-
- }
-
- else
-
- {
-
- throw new ArgumentNullException("没有指定文件名异常");
-
- }
-
- return result;
-
- }
-
- }
-
- }
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace IODemo
{
/// <summary>
/// 说明:基于字符的方式读写流的例子。
/// 作者:周公
/// 日期:2008-6-30
/// 原文地址:http://blog.youkuaiyun.com/zhoufoxcn
/// </summary>
public class TextDemo
{
private string fileName;
/// <summary>
/// 要进行读写的文件全路径
/// </summary>
public string FileName
{
get { return fileName; }
set { fileName = value; }
}
/// <summary>
/// 基于字符的方式写文件流
/// </summary>
/// <param name="message"></param>
public void WriteFile(string message)
{
if (fileName != null)
{
FileInfo file = new FileInfo(fileName);
FileStream stream = null;
StreamWriter writer = null;
if (!file.Exists)
{
//如果不存在指定文件则创建指定文件
stream = file.Create();
}
else
{
//否则打开打开文件流
stream = file.OpenWrite();
}
writer = new StreamWriter(stream);
//将字符串写入流中
writer.Write(message);
writer.Close();
stream.Close();//关闭流
}
else
{
throw new ArgumentNullException("没有指定文件名异常");
}
}
/// <summary>
/// 基于字符的方式读文件流
/// </summary>
/// <returns></returns>
public string ReadMessage()
{
string result = string.Empty;
if (fileName != null)
{
FileInfo file = new FileInfo(fileName);
FileStream stream = file.OpenRead();
StreamReader reader = new StreamReader(stream);
//一次性读入所有字符
result = reader.ReadToEnd();
reader.Close();
stream.Close();//关闭流
}
else
{
throw new ArgumentNullException("没有指定文件名异常");
}
return result;
}
}
}
1198

被折叠的 条评论
为什么被折叠?



