把文本读出来了,可不知道怎么一行一行分开,程序如下:
static void Main(string[] args)
{
byte[] m_b = new byte[10000];
char[] m_c = new char[10000];
try
{
FileStream m_Fs = new FileStream(@"E:\HuaXia\source\6304-STMT30-20070515.dat", FileMode.Open);
m_Fs.Seek(0,SeekOrigin.Begin);
m_Fs.Read(m_b,0,10000);
}
catch(IOException ex)
{
Console.WriteLine("there is an IOException");
Console.WriteLine(ex.Message);
Console.ReadLine();
return;
}
System.Text.Encoding.GetEncoding("GB2312");
Decoder m_Dec = Encoding.Default.GetDecoder();
m_Dec.GetChars(m_b,0,m_b.Length,m_c,0);
Console.WriteLine("read from file succed!");
Console.WriteLine(m_c);
Console.ReadLine();
return;
哪位仁兄给点指点吧,最好能在源程序上加点东本.在线等,马上给分
static void Main(string[] args)
{
byte[] m_b = new byte[10000];
char[] m_c = new char[10000];
try
{
FileStream m_Fs = new FileStream(@"E:\HuaXia\source\6304-STMT30-20070515.dat", FileMode.Open);
m_Fs.Seek(0,SeekOrigin.Begin);
m_Fs.Read(m_b,0,10000);
}
catch(IOException ex)
{
Console.WriteLine("there is an IOException");
Console.WriteLine(ex.Message);
Console.ReadLine();
return;
}
System.Text.Encoding.GetEncoding("GB2312");
Decoder m_Dec = Encoding.Default.GetDecoder();
m_Dec.GetChars(m_b,0,m_b.Length,m_c,0);
Console.WriteLine("read from file succed!");
Console.WriteLine(m_c);
Console.ReadLine();
return;
哪位仁兄给点指点吧,最好能在源程序上加点东本.在线等,马上给分
sr.ReadLine();
StreamWriter sw = new StreamWriter(fs);
sw.AutoFlush = true;
string data=sw.ReadLine();//这样读一行
FileStream fs = new FileStream("c:\\updatalog.txt", FileMode.OpenOrCreate);
StreamReader sw = new StreamReader(fs);
sw.AutoFlush = true;
string data=sw.ReadLine();//这样读一行
如果是 gb2312的話,你要指定流的編號格式的,因為默認是 unicode.
StreamReader sr = new StreamReader("TestFile.txt",System.Text.Encoding.ASCII);
sr.ReadLine();
这样来读就行了,
System.Text.Encoding.GetEncoding("GB2312");