You can not do something like memcpy in C++.You can say 
String str = socket.toString();
or String str = socket.getAddress().toString();

解决方案 »

  1.   

    String str = socket.toString();
    用这个可以保存了
    但要想再让它变成原来的类型怎么转换呀??
      

  2.   

    Are you complicating your own life? If you really want to save an object and bring it back later on, you can make it serilizable. However, Socket is not a serilizable object, you cannot save it. After all, I think the only reason a person want to "save" a socket is because he doesn't know what he is doing.
      

  3.   

    你看到的内容大概是java.net.Socket::toString()方法输出的内容你可以把Socket本身直接存在一个“容器”里,如java.util.Collection
    的实现类(如java.util.Vector),用的时候再取出来