大家好,我有一个很大的问题,直到现在没有人帮助我。 首先我想打开 XXX.vmg(这个扩展名来自诺基亚 PC 套件)文件并读取它然后将它写入 richtextbox。我写的代码没有错误,richtextbox也没有结果
这是我的代码
FileStream file = new FileStream("c:\\XXX.vmg", FileMode.OpenOrCreate, FileAccess.Read);
StreamWriter sw = new StreamWriter(fileW);
StreamReader sr = new StreamReader(file);
string s1 = sr.ReadToEnd();
string[] words = s1.Split(' ');
for (int i=0; i<words.length; i++)
richTextBox1.Text +=Envirment.NewLine + words[i];
`enter code here`
the output at richtextbox just blank line
请您参考如下方法:
对 VMG 文件进行了一些谷歌搜索,您遇到了一些问题:
VMG 包含没有字节顺序标记的小端 Unicode。这意味着除非您指定编码,否则
ReadToEnd或ReadAllText等标准文本方法将不起作用。获得编码后,VMG 会包含一堆 SMS header ,如 VMSG、VCARD 和 STATUS block 。我不知道你想要完成什么,所以你必须决定如何处理这些 block 。
但是,您可以将文件作为文本阅读:
string folderPath = @"C:\path\to\your\VMG\folder";
using (StreamReader r = new StreamReader(Path.Combine(folderPath, @"filename.vmg"), Encoding.Unicode))
{
string s;
while ((s = r.ReadLine()) != null)
{
// s is a readable SMS block, what do you want to do with it?
}
}
