// 俺的一个函数: private static string LoadFromFile(string str) { FileStream fs = new FileStream(str, FileMode.Open); StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("GB2312")); // 这一句就是了 return sr.ReadToEnd(); }
我这里不是从文件中读数据。数据已经在字符串中,但是由于有中文所以显示时候乱码。 由于要直接操作文件流的位置,我使用了 fs = new FileStream(s,FileMode.Open,FileAccess.Read)来读取数据,所以各位兄台的方法不太适用。还有什么 办法呢?
System.IO.FileStream fs2 =new System.IO.FileStream("e:\\bb.txt",System.IO.FileMode.Open,System.IO.FileAccess.Read); System.IO.BinaryReader r =new System.IO.BinaryReader(fs2); byte[] b=new byte[fs2.Length]; b=r.ReadBytes((int)fs2.Length); string t =System.Text.Encoding.Default.GetString(b);//this is your needs
private static string LoadFromFile(string str)
{
FileStream fs = new FileStream(str, FileMode.Open);
StreamReader sr = new StreamReader(fs,
System.Text.Encoding.GetEncoding("GB2312")); // 这一句就是了
return sr.ReadToEnd();
}
由于要直接操作文件流的位置,我使用了 fs = new FileStream(s,FileMode.Open,FileAccess.Read)来读取数据,所以各位兄台的方法不太适用。还有什么
办法呢?
System.IO.BinaryReader r =new System.IO.BinaryReader(fs2);
byte[] b=new byte[fs2.Length];
b=r.ReadBytes((int)fs2.Length);
string t =System.Text.Encoding.Default.GetString(b);//this is your needs
private void button5_Click(object sender, System.EventArgs e)
{
try
{
IDataObject data = Clipboard.GetDataObject();
if(data.GetDataPresent(DataFormats.Html))
{
string dataHtml = data.GetData(DataFormats.Html,true) as string;
MessageBox.Show(dataHtml);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
}
问题真是郁闷,怀疑是不是一个bug.