高手看看这段代码如何支持中文显示.
午夜恋曲 2013-07-12 02:53:01 高手看看这段代码如何支持中文显示.
程序作用主要是自动监测C:\MSSQLTips下是否有文本文件,如果发现有自动读取里面内容并且显示出来,现在的问题是,只能读取英文或者数字,如果是中文,会显示??????,请教大家如何修改。
// MessageBox.Show(e.Name);
try
{
using (StreamReader sr = new StreamReader(@"C:\MSSQLTips\" + e.Name))
{
String line = sr.ReadToEnd();
sr.Dispose();
sr.Close();
string line2 = line.Replace("\r\n", "\u0000");
Packet packet = new Packet(0x7025);
packet.WriteUInt8((byte)7);
packet.WriteUInt8((byte)0);
packet.WriteAscii(line2);
if (!string.IsNullOrEmpty(line2))
{
Agent.Send(packet);
}
System.IO.File.Delete(@"C:\MSSQLTips\" + e.Name);
}
}
catch (Exception ex)
{
MessageBox.Show("error" + ex);
}
}
private void button9_Click_1(object sender, EventArgs e)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\MSSQLTips\";
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size;
watcher.Filter = "*.txt";
//watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
watcher.InternalBufferSize = 64000;
label31.Text = "自动公告启动";
}