{
string aa = "我们很好";
// toBase64
string bb = Convert.ToBase64String(Encoding.UTF8.GetBytes(aa));
print(bb);
byte[] cc = Convert.FromBase64String(bb);
string ee = UTF8Encoding.UTF8.GetString(cc);
print(ee);
string st = "是肯德基";
byte[] bytes = UTF8Encoding.UTF8.GetBytes(st);
//string aa = Convert.ToBase64String(bytes);
//byte[] cc = Convert.FromBase64String(aa);
string dd = UTF8Encoding.UTF8.GetString(bytes);
print(dd);
}
void testZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream gzip = new GZipOutputStream(ms);
byte[] binary = Encoding.UTF8.GetBytes("sddddddddd");
gzip.Write(binary, 0, binary.Length);
gzip.Close();
byte[] press = ms.ToArray();
Debug.Log(Convert.ToBase64String(press) + " " + press.Length);
GZipInputStream gzi = new GZipInputStream(new MemoryStream(press));
MemoryStream re = new MemoryStream();
int count = 0;
byte[] data = new byte[4096];
while ((count = gzi.Read(data, 0, data.Length)) != 0)
{
re.Write(data, 0, count);
}
byte[] depress = re.ToArray();
Debug.Log(Encoding.UTF8.GetString(depress));
}
public void TestSaveData()
{
string str = Application.dataPath + "/test.xls";
byte[] byData;
char[] charData;
try
{
FileStream aFile = new FileStream("E:/proj/CMZY/CMZY_TransportTruck/Temp2.txt", FileMode.Create);
string st = "是肯德基";
byData = UTF8Encoding.UTF8.GetBytes(st);
//byData = new byte[charData.Length*2];
//Encoder e = Encoding.UTF8.GetEncoder();
// e.GetBytes(charData, 0, charData.Length, byData, 0, true);
// Move file pointer to beginning of file.
aFile.Seek(0, SeekOrigin.Begin);
aFile.Write(byData, 0, byData.Length);
}
catch (IOException ex)
{
//Console.WriteLine("An IO exception has been thrown!");
//Console.WriteLine(ex.ToString());
//Console.ReadKey();
return;
}
}