java关闭io流,HttpURLConnection关闭IO流

I am new to Java and HttpURLConnection. Should I close the opened IO streams before dropping the connection. If I close the streams, should I need to drop the connection as well? Which is the proper way of implementation?

try {

String uri = "http://localhost:8081/RESTEASY/saju/post/text";

URL url = new URL(uri);

connection =

(HttpURLConnection) url.openConnection();

connection.setRequestMethod("POST");

connection.setRequestProperty("Accept", "text/plain");

connection.setRequestProperty("Content-Type", "text/plain");

connection.setDoOutput(true);

OutputStream os = connection.getOutputStream();

//bla bla

System.out.println(connection.getResponseCode());

InputStream iStream = connection.getInputStream();

//bla

你可能感兴趣的:(java关闭io流)