我正在尝试使用以下方法获取URL内容的大小:URLConnectionconn=null;URLurl=null;url=newURL("https://dl.dropboxusercontent.com/u/90210205/Default.html");conn=url.openConnection();conn.connect();InputStreamin=newBufferedInputStream(url.openStream());intfileSize=conn.getContentLength();System.out.println("Filesize"+fileS
我有一个URL,当我在浏览器中输入该URL时,它可以完美地打开图像。但是当我尝试下面的代码时,我得到的getContentLength()为-1:URLurl=newURL(imageUrl);HttpURLConnectionconnection=(HttpURLConnection)url.openConnection();//determinetheimagesizeandallocateabufferintfileSize=connection.getContentLength();请指导我这背后的原因是什么? 最佳答案 如
这是我的代码:url=paths[0];HttpURLConnectionconnection=(HttpURLConnection)url.openConnection();intlength=connection.getContentLength();//igetnegetivelengthInputStreamis=(InputStream)url.getContent();byte[]imageData=newbyte[length];intbuffersize=(int)Math.ceil(length/(double)100);intdownloaded=0;intread