URL url = new URL(pic);
HttpURLConnection httpconn = (HttpURLConnection) url.openConnection();
httpconn.connect();
Gether.jLabel_Down.setText("正在下载 "+time+"...");
System.out.println("服务器返回"+httpconn.getContentLength());
ds = new DataInputStream(httpconn.getInputStream());
out = new DataOutputStream(new FileOutputStream(file));
int size = 0,j = 0;
System.out.println("得到"+ds.available());
while ((size = ds.read()) != -1) {
out.write(size);
//j = j + size;
//System.out.println(ds.read());
//show(j,httpconn);
}请问怎样每次读到了多少个字节呢?还有输出结果是
服务器返回256225
得到2631
HttpURLConnection httpconn = (HttpURLConnection) url.openConnection();
httpconn.connect();
Gether.jLabel_Down.setText("正在下载 "+time+"...");
System.out.println("服务器返回"+httpconn.getContentLength());
ds = new DataInputStream(httpconn.getInputStream());
out = new DataOutputStream(new FileOutputStream(file));
int size = 0,j = 0;
System.out.println("得到"+ds.available());
while ((size = ds.read()) != -1) {
out.write(size);
//j = j + size;
//System.out.println(ds.read());
//show(j,httpconn);
}请问怎样每次读到了多少个字节呢?还有输出结果是
服务器返回256225
得到2631
解决方案 »
- Java中byte,int十六进制表示问题
- 急求 公园租车 思路或 代码
- 这段代码什么意思?比较简单
- JDBC和JNDI有哪些主要区别?
- 使用AlloyLookAndFeel后在登陆框输入中文为什么会抛出异常???
- 菜问:下载jdk的时候是分别下载JDK和JRE,这个JRE是必须的吗?如果是的话为什么要分开下载?
- 简单问题:jbuilder7中的jTextArea怎么设置scrollbar属性
- 请问在JBuilder6中如何使用外部导入的包??
- java中的构建器是个什么概念????
- Java的包究竟该怎么用
- DatagramSocket 自己给自己发消息包有异常
- DatagramSocket 自己给自己发消息包有异常 但是getMessage却是null...
int offset = 0;
contentLength = httpconn.getContentLength();
byte data[] = data = new byte[4096];
while (offset < contentLength) {
if (contentLength - offset >= data.length) {
byteRead = ds.read(data, 0, data.length);
} else {
byteRead = ds.read(data, 0, contentLength - offset);
}
if (byteRead == -1) {
//error
ds.close();
out.close();
}
out.write(data, 0, byteRead);
offset+= byteRead;
}
ds.close();
out.close();
URL url = new URL(pic);
HttpURLConnection httpconn = (HttpURLConnection) url.openConnection();
httpconn.connect();
Gether.jLabel_Down.setText("正在下载 "+time+"...");
System.out.println("服务器返回"+httpconn.getContentLength());
ds = new DataInputStream(httpconn.getInputStream());
out = new DataOutputStream(new FileOutputStream(file));
byte[] b=new byte[500];//应该有定义每次写多少内容,大小你也根据原内容ds来定义
int size = 0,j = 0;
System.out.println("得到"+ds.available());
while ((size = ds.read(b)) != -1) {
out.write(b);//写入的内容
//j = j + size;
//System.out.println(ds.read());
//show(j,httpconn);
}