---
title: "Response的OutputStream和Writer"
author: "wiki_more"
date: "2012-04-11T10:48:09Z"
tags: []
categories: ["编程语言"]
slug: "response-outputstream-writer"
draft: false
lastmod: "2012-04-23T21:27:17Z"
id: 1483129
url: "https://wikimore.iteye.com/blog/1483129"
---

```
public ServletOutputStream getOutputStream() throws IOException {
  if (this.servletOutputStream == null) {
     this.servletOutputStream = new ServletOutputStreamAdapter(this.exchange.getResponseBody());
   }
    return this.servletOutputStream;
  }
  public PrintWriter getWriter() throws IOException {
    if (this.writer == null) {
      if (this.characterEncoding != null) {
        this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(this.exchange.getResponseBody(), this.characterEncoding)));
       }
     else {
       this.writer = new PrintWriter(this.exchange.getResponseBody());
       }
   }
    return this.writer;
}
```

 所以用完以后要关闭