简体   繁体   中英

C# byte array doesn't understand by Java

i am using memcache , for communicating between java and c#. c# put data into memcache in byte[] format and from java application trying to read that byte array but in Java im getting String Object . Sample :- C# code

MemcachedClient _mc = new MemcachedClient();
_mc.Serverlist = { "127.0.0.1:11211" }
byte[] stestValue = GetBytes("india");
m_c.set("key1",stestValue);

private byte[] GetBytes(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}

Java Code :-// to fetch data which we set in memcache having key :- Key1

MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));

Object value = mcc.get("key1");

here we get string object in Value rather than byte[] .

是的,我尝试从中获取byte [],但是此字节数组的长度与c#字节数组不同。我的要求是按字节的长度来解析字节数组,因此要求是c#中byte []的长度= in in byte []中的长度Java的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM