62,614
社区成员
发帖
与我相关
我的任务
分享
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InputStream in = request.getInputStream();
int bytesRead = 0;
while ((bytesRead = in.read()) != -1) {
try {
bos.write(bytesRead);
} catch (Exception e) {
}
}
byte[] bt = bos.toByteArray();
System.out.println(new String(bt, "GBK"));
bos.close();
in.close();
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
ByteArrayOutputStream bot = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bot);
oos.writeObject(new Date());
oos.writeObject(3.1415926);
oos.writeObject(2011);
oos.writeObject("Hello World");
oos.close();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bot.toByteArray()));
while(true){
try{
Object obj = ois.readObject();
System.out.println(obj);
}catch (Exception e) {
e.printStackTrace();
ois.close();
break;
}
}
}