Use BinaryWriter to write the file the first character is garbled what is the reason?

Source: Internet
Author: User
Try
{
   FileStream myfs = new FileStream (filepath + @ "\patchmove.ini", FileMode.Create);
   BinaryWriter MYBW = new BinaryWriter (MYFS);
   Mybw.write ("The Valley of the E:\ Dragon");
   Mybw.close ();
   Myfs.close ();
}
catch (Exception) {}

The code is like this

Well, that's what the paper says.

The first garbled in the end how to come to think Impassability


There are two solutions:

Methods one, using StreamWriter

Try
 {
    FileStream myfs = new FileStream (filepath + @ "\patchmove.ini", FileMode.Create);
    <span style= "Color:rgb (51, 51, 51); Font-family:helvetica, Tahoma, Arial, Sans-serif; font-size:14px; line-height:24px; Background-color:rgb (245, 245, 245); >STREAMWRITER</SPAN>MYBW = new <span style= "Color:rgb" (51, 51, 51); Font-family:helvetica, Tahoma, Arial, Sans-serif; font-size:14px; line-height:24px; Background-color:rgb (245, 245, 245); >StreamWriter</span> (MYFS);
    Mybw.write (<span style= "Font-family:helvetica, Tahoma, Arial, Sans-serif;" > "e:\ Dragon Valley" </span>);
    Mybw.close ();
    Myfs.close ();
}
catch (Exception) {}

Method Two, change to Mybw.write (path. ToCharArray ());

Try
{
   FileStream myfs = new FileStream (filepath + @ "\patchmove.ini", FileMode.Create);
   <span style= "Font-family:helvetica, Tahoma, Arial, Sans-serif; Background-color:rgb (245, 245, 245); >STREAMWRITER</SPAN>MYBW = new <span style= "Font-family:helvetica, Tahoma, Arial, Sans-serif; Background-color:rgb (245, 245, 245); >StreamWriter</span> (MYFS);
   Mybw.write (<span style= "Color:rgb" (Wuyi, Wuyi); Font-family:helvetica, Tahoma, Arial, Sans-serif; font-size:14px; Lin e-height:24px; Background-color:rgb (245, 245, 245); > "E:\ the Valley of the Dragon". ToCharArray () </span>);
   Mybw.close ();
   Myfs.close ();
}
catch (Exception) {}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.