1. 程式人生 > >由於ServerIP老是變來變去,所以,要在本地進行配置。

由於ServerIP老是變來變去,所以,要在本地進行配置。

src pen 寫入 fig alt 配置 u3d 讀取 com

1.

技術分享

2.

技術分享

3.

private void readConfig()
{
string cfgpath = System.IO.Path.Combine(Environment.CurrentDirectory + "\\u3d", "config.txt");
//讀取editConfig裏面的IP
System.IO.FileInfo fi = new System.IO.FileInfo(cfgpath);
long len = fi.Length;

System.IO.FileStream fs = new System.IO.FileStream(cfgpath, System.IO.FileMode.Open);
byte[] buffer = new byte[len];
fs.Read(buffer, 0, (int)len);//把文件流fs寫入到緩沖區buffer中
fs.Close();
string str = Encoding.UTF8.GetString(buffer);//unicode是亂碼,utf是正常字符串
UserData.serverIP = str;
}

由於ServerIP老是變來變去,所以,要在本地進行配置。