Q on filestream and streamreader unicode
HI all of u,, I have big problem until now no body helped me. firstly I want to open XXX.vmg (this extension come from Nokia PC Suite) file and read it then write it in richtextbox. I wrote the code there is no error and also there is no reault in the richtextbox
here is my c开发者_JAVA技巧ode
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
Did a bit of Googling for VMG files, and you have a few problems:
VMGs contain little-endian Unicode with no byte-order marks. This means standard text methods like
ReadToEnd
orReadAllText
won't work unless you specify an encoding.Once you've got the encoding, VMGs include a bunch of SMS headers like VMSG, VCARD, and STATUS blocks. I don't know what you're trying to accomplish, so you will have to decide what to do with these blocks.
However, you can read the file as text with:
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?
}
}
精彩评论