日期:2014-05-17 浏览次数:20724 次
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
PrintWriter out = response.getWriter();
byte record[] = null;
String r = "";
try{
dos.writeInt(2);//记录个数
dos.writeInt(0);//任务类型
dos.writeUTF("霸三国");//名称
dos.writeInt(1);// 对话次数、物品件数、杀怪个数
dos.writeInt(2);//任务类型
dos.writeUTF("贞子");//名称
dos.writeInt(1);// 对话次数、物品件数、杀怪个数
record = bos.toByteArray();
r = Arrays.toString(record);
System.out.println(r);
//打印出来的数组:
//[0, 0, 0, 2, 0, 0, 0, 0, 0, 9, -23, -100, -72, -28, -72, -119, -27, -101, -67, 0, 0, 0, 1, 0, 0, 0, 2, 0, 6, -24, -76, -98, -27, -83, -112, 0, 0, 0, 1]
request.setAttribute("bytearray", r);
request.getRequestDispatcher("/ba.jsp").forward(request, response);
}catch (Exception e){
e.printStackTrace();
}finally {
dos.close();
bos.close();
}