把Map转换成byte数组,使用 ByteArrayOutputStream 和 ObjectOutputStream
Map<String,String> map = new HashMap<String,String>(); map.put("name","aaa"); map.put("age","11"); try { byte[] bt = null; ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeObject(map); bt=os.toByteArray(); oos.close(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }