求解!!!
请帮忙看一下这个程序,不知为何在我标注*****的那行总是抛出一个IOException,实在调不出来了,那位好心的大哥帮忙指点一下?先谢了!!!!!!!!!
public int getCount() throws Exception
{
// Get the server URL
java.net.URL url =null;
java.net.URLConnection con =null;
byte buf[]= null;
DataOutputStream dataOut=null;
url = new java.net.URL(m_url);
// Attempt to connect to the host
con = url.openConnection();
// Set the session ID if necessary
if (m_cookie != null) {
con.setRequestProperty("cookie", m_cookie);
}
// Initialize the connection
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
// Data will always be written to a byte array buffer so
// that we can tell the server the length of the data
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
// Create the output stream to be used to write the
// data to our buffer
DataOutputStream out = new DataOutputStream(byteOut);
// Send any data to the servlet here
// Flush the data to the buffer
out.flush();
// Get our buffer to be sent
buf = byteOut.toByteArray();
// Set the content that we are sending
con.setRequestProperty("Content-type",
"application/octet-stream");
// Set the length of the data buffer we are sending
con.setRequestProperty("Content-length",
"" + buf.length);
// Get the output stream to the server and send our
// data buffer
***** dataOut = new DataOutputStream(con.getOutputStream());
dataOut.write(buf);
// Flush the output stream and close it
dataOut.flush();
dataOut.close();
// Get the input stream we can use to read the response
DataInputStream in =
new DataInputStream(con.getInputStream());
// Read the data from the server
int count = in.readInt();
// Close the input stream
in.close();
// Get the session cookie if we haven't already
if (m_cookie == null) {
String cookie = con.getHeaderField("set-cookie");
if (cookie != null) {
m_cookie = parseCookie(cookie);
System.out.println("Setting session ID=" + m_cookie);
}
}
return count;
}