我使用 PrintWriter out 对象。我写数据 out.println(some data) 并用 out.close 关闭它
URL url = new URL(myurl);
URLConnection connection = null;
PrintWriter out = null; BufferedReader br = null; connection = url.openConnection(); connection.setDoOutput(true);
out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()),true);
while(iterations) {
//print data on writer
out.println(object);
}
//closig print writer
out.flush();
out.close();
//Response from server
br = new BufferedReader(new InputStreamReader(connection.getInputStream())); // Get Exception in //this line EOF Exception
String temp;
while(temp = br.readLine() !=null) {
//do something
}
br.close();