StreamReader srAsciiFromStream = new StreamReader(
(System.IO.Stream)File.OpenRead("C:\\Temp\\Test.txt"),
System.Text.Encoding.Default);
(System.IO.Stream)File.OpenRead("C:\\Temp\\Test.txt"),
System.Text.Encoding.Default);
解决方案 »
- 如何获取一个Datatable中拥有最小值且大于0的行?
- vs2005里,cs代码编辑界面,左边断点处有个蓝色向上箭头,怎么去除?
- 关于XSL嵌套循环中条件判断的问题
- 算法:返回一个数组前N个数中的最大值,最多使用log 2 (n) [2是底数,n是指数] 次递归调用
- 当前线程处于堆栈溢出状态,因此无法计算表达式的值。谁遇到过这种错误啊?
- 我要在window service服务启动后显示一个窗体界面,怎么做?
- 请教各路神仙!怎么实现像msn里面的代理服务器设置?
- 水晶报表部署问题?,请成功部署过的朋友帮帮我吧!
- WPF,这种点击事件如何获取事件源
- 请教:如何在子窗体中调用父窗体中的方法?
- 这个C++的函数在C#中怎么申明.
- 如何查组合键值?
using System.IO;class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt"; try
{
if (File.Exists(path))
{
File.Delete(path);
} using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine("This");
sw.WriteLine("is some text");
sw.WriteLine("to test");
sw.WriteLine("Reading");
} using (StreamReader sr = new StreamReader(path,System.Text.Encoding.
Default))
{
//This is an arbitrary size for this example.
char[] c = null; while (sr.Peek() >= 0)
{
c = new char[5];
sr.Read(c, 0, c.Length);
//The output will look odd, because
//only five characters are read at a time.
Console.WriteLine(c);
}
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
System.Text.Encoding.GetEncoding("GB2312")
这个问题一般可以调整StreamReader实例的 System.Text.Encoding 参数来解决,
可以试一下这两个:System.Text.Encoding.Default
System.Text.Encoding.UTF8
StreamReader sr =new StreamReader((System.IO.Stream)File.OpenRead(path),System.Text.Encoding.GetEncoding("GB2312"));