public void download(String cookie,String parameter){
RandomAccessFile raf = null;
DataInputStream dis = null;
try {
URL ipUrl = new URL("http://218.83.246.48/system.DataBackupAction.do");
HttpURLConnection ipConn = (HttpURLConnection) ipUrl
.openConnection();
//设置超时
ipConn.setReadTimeout(10000);
ipConn.setConnectTimeout(1000); ipConn.setDoInput(true);
ipConn.setDoOutput(true);
ipConn.setRequestProperty("Cookie", cookie); OutputStream out = ipConn.getOutputStream();
out.write(parameter.getBytes());//GET写参数
out.flush();
out.close();
ipConn.connect();
byte[] temp = new byte[1024];
dis = new DataInputStream(ipConn.getInputStream());
raf = new RandomAccessFile(new File("temp.zip") , "rw");
while(true){
System.out.println(raf.getFilePointer());
[color=#FF0000]int length = dis.read(temp);//在这里读的时候,由于网络可能很卡,就时1024字节也读的很慢,就像是整个程序死在那里了,用ReadTimeOut没用,这是在getInputStream()的时候起作用的,那怎么办???
System.out.println(length);
if(length == -1){
break;
}
raf.write(temp,0,length);
}
}catch(SocketTimeoutException e){
System.out.println(e.getMessage());
e.printStackTrace();
}catch(SocketException e){
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally{
if(dis != null)
try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
if(raf != null)
try {
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}各位大哥帮帮忙!!!!!!!
RandomAccessFile raf = null;
DataInputStream dis = null;
try {
URL ipUrl = new URL("http://218.83.246.48/system.DataBackupAction.do");
HttpURLConnection ipConn = (HttpURLConnection) ipUrl
.openConnection();
//设置超时
ipConn.setReadTimeout(10000);
ipConn.setConnectTimeout(1000); ipConn.setDoInput(true);
ipConn.setDoOutput(true);
ipConn.setRequestProperty("Cookie", cookie); OutputStream out = ipConn.getOutputStream();
out.write(parameter.getBytes());//GET写参数
out.flush();
out.close();
ipConn.connect();
byte[] temp = new byte[1024];
dis = new DataInputStream(ipConn.getInputStream());
raf = new RandomAccessFile(new File("temp.zip") , "rw");
while(true){
System.out.println(raf.getFilePointer());
[color=#FF0000]int length = dis.read(temp);//在这里读的时候,由于网络可能很卡,就时1024字节也读的很慢,就像是整个程序死在那里了,用ReadTimeOut没用,这是在getInputStream()的时候起作用的,那怎么办???
System.out.println(length);
if(length == -1){
break;
}
raf.write(temp,0,length);
}
}catch(SocketTimeoutException e){
System.out.println(e.getMessage());
e.printStackTrace();
}catch(SocketException e){
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally{
if(dis != null)
try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
if(raf != null)
try {
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}各位大哥帮帮忙!!!!!!!
呢。期待高人。
下载