HttpURLConnection中connection.getInputStream()报异常FileNotFoundException

来源:互联网 发布:网络正规兼职写手 编辑:程序博客网 时间:2024/06/05 03:07

HttpURLConnection中connection.getInputStream()报异常FileNotFoundException,各位帮忙看看
代码如下:
String httpUrl = "http://192.168.1.102:8080/http/";


//获得的数据
String resultData = "";
URL url = null;
try
{
//构造一个URL对象
url = new URL(httpUrl);

}
catch (MalformedURLException e)
{
Log.e(DEBUG_TAG, "MalformedURLException");
}

if (url != null)
{
try {
//使用HttpURLConnection打开连接
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
//得到读取的内容(流)
InputStreamReader in = new InputStreamReader(urlConn.getInputStream());
// 为输出创建BufferedReader
BufferedReader buffer = new BufferedReader(in);
String inputLine = null;
//使用循环来读取获得的数据
while (((inputLine = buffer.readLine()) != null))
{
//我们在每一行后面加上一个"\n"来换行
resultData += inputLine + "\n";
}
//关闭InputStreamReader
in.close();
//关闭http连接
urlConn.disconnect();
//设置显示取得的内容
if (resultData != null)
{
m_TextView.setText(resultData);

}
else
{
m_TextView.setText("读取的内容为NULL");
}
}
catch (IOException e)
{
Log.e(DEBUG_TAG, "IOException");
}
}
else
{
Log.e(DEBUG_TAG, "Url NULL");
}


输出的提示信息如下:
10-12 10:25:38.264: I/Choreographer(1728): Skipped 67 frames!  The application may be doing too much work on its main thread.
10-12 10:25:39.244: I/Choreographer(1728): Skipped 86 frames!  The application may be doing too much work on its main thread.
10-12 10:25:39.944: E/Http1(1728): IOException
10-12 10:25:40.414: I/Choreographer(1728): Skipped 178 frames!  The application may be doing too much work on its main thread.
10-12 10:25:41.324: I/Choreographer(1728): Skipped 50 frames!  The application may be doing too much work on its main thread.

0 0
原创粉丝点击