隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827218
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          package serializable;

           

          import java.io.ByteArrayInputStream;

          import java.io.ByteArrayOutputStream;

          import java.io.ObjectInputStream;

          import java.io.ObjectOutputStream;

           

          public class ObjectToIO

          {

              /**

               *

               * 對象轉Byte數組

               *

               * @param obj

               *

               * @return

               *

               * @throws Exception

               *

               */

              public static byte[] objectToBytes(Object obj) throws Exception

              {

                  // logger.debug("objectToString called ");

                  ByteArrayOutputStream out = new ByteArrayOutputStream();

                  ObjectOutputStream sOut = new ObjectOutputStream(out);

                  sOut.writeObject(obj);

                  sOut.flush();

                  byte[] bytes = out.toByteArray();

                  // logger.debug(bytes.toString());

                  return bytes;

           

              }

           

              /**

               *

               * 字節數組轉對象

               * @param content

               *

               * @return

               *

               * @throws Exception

               *

               */

           

              public static Object bytesToObject(byte[] bytes) throws Exception

              {

                  // logger.debug("bytesToObject called ");

                  // byteobject

                  ByteArrayInputStream in = new ByteArrayInputStream(bytes);

                  ObjectInputStream sIn = new ObjectInputStream(in);

                  return sIn.readObject();

           

              }

          }

          轉自:http://wenku.baidu.com/view/1e0a23b465ce050876321373.html

          posted on 2011-09-16 10:51 Ke 閱讀(5342) 評論(0)  編輯  收藏 所屬分類: java 、webservice
          主站蜘蛛池模板: 鄄城县| 永和县| 营山县| 龙江县| 沈阳市| 鸡泽县| 乐安县| 海南省| 云霄县| 墨竹工卡县| 郓城县| 凤冈县| 肇庆市| 和静县| 勐海县| 达孜县| 腾冲县| 保康县| 永定县| 资兴市| 崇仁县| 平陆县| 湄潭县| 五莲县| 运城市| 子长县| 吉水县| 盐城市| 凤山县| 辽宁省| 南雄市| 兴城市| 麻江县| 津南区| 湘潭县| 临夏市| 东丰县| 阳信县| 建瓯市| 宣恩县| 北流市|