get web url content length
2010-10-11 10:13
246 查看
public class ClientWithResponseHandler {
public static void main(String[] args) {
test("http://www.google.com");
}
public static String test(String url) {
String result = "";
try {
URL httpurl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) httpurl.openConnection();
InputStream i=httpConn.getInputStream();
int l=0;
while(i.read()!=-1){
l++;
}
System.out.println(l);
i.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
public static void main(String[] args) {
test("http://www.google.com");
}
public static String test(String url) {
String result = "";
try {
URL httpurl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) httpurl.openConnection();
InputStream i=httpConn.getInputStream();
int l=0;
while(i.read()!=-1){
l++;
}
System.out.println(l);
i.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
相关文章推荐
- HttpURLConnection.getContentLength()为-1 解决方法
- 关于inputStream.available()与HttpURLConnection.getContentLength()方法获取下载文件的大小
- HttpURLConnection getContentLength();返回时-1或者是0
- 使用HttpURLConnection的getContentLength()方法返回-1??
- Android2.2以上的版本HttpURLConnection.getContentLength()获取的size跟下载下来的file的legth不相等
- HttpURLConnection getContentLength();返回时-1或者是0
- 下载网络文件HttpURLConnection.getContentLength()大小为 -1
- HttpURLConnection getContentLength();返回时-1或者是0
- http urlconnection getcontentlength总返回值为-1
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- Android HttpURLConnection.getContentLength() 等于 -1
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0
- 关于inputStream.available()与HttpURLConnection.getContentLength()方法获取下载文件的大小
- HttpURLConnection getContentLength();返回时-1或者是0
- HttpURLConnection getContentLength();返回时-1或者是0